[IPython-user] Re: Auto-discard notification

Fernando Perez fperez at colorado.edu
Thu Dec 18 13:15:19 CST 2003


Hi Maciej,

I'm responding to you CC'ing the list, but please note that your message did 
NOT go to the list originally.  The ipython lists do not allow non-subcriber 
postings because of the inordinate amount of spam we were getting.

If you are interested in following the discussions, I'd encourage you to 
subscribe (both user and dev lists are very low volume).

> ------------------------------------------------------------------------
> 
> Subject: Qs: ctrl-c, stale version of program in memory
> From: Maciej Kalisiak <mac at dgp.toronto.edu>
> Date: Thu, 18 Dec 2003 13:39:47 -0500
> To: ipython-user at scipy.net
> 
> 
> I like IPython very much, but have two issues which prevent me from
> using it for all my work, something I would like to do.  The problems
> are probably just my lack of understanding of how IPython works, so if
> someone could enlighten me.
> 
> First, I believe that on quite a few occasions, I would run my program
> under IPython, find a bug, modify code, and run it again (in same
> instance of IPython).  For some strange reason the edited changes do not
> taken hold, as if IPython somehow cached the old version of the program,
> and kept using it despite the newer source.  On other occasions it works
> normally.  What am I missing?

The question is how you 'run' your program.  Are you using the @run magic? Or 
the import keyword?  If you user @run <file>, you are guaranteed that the 
source for <file> IS reloaded fresh everytime.  However, any module imported 
by <file> which has been modified is NOT reloaded.  This is not an IPython 
limitation, it is how Python's import system works at the core.  IPython does 
offer a deep reload command, @dreload, to assist with this.

But I agree that even I sometimes find myself quitting and restarting ipython 
just to be 100% sure that I get a fresh copy of some deeply nested code where 
I've made changes at many levels.  Because of python's handling of imports, 
deep reloading is very tricky to get right and not 100% reliable.

But again, in this regard you should not see in ipython any limitation which 
is not there in native python to begin with.  If you think you have an example 
to the contrary, please give more specific details so I can look into it as a bug.

> Second, is there a way to have "ctrl-c", or some other keystroke combo
> drop from a running program to IPython/pdb, so I can inspect state of
> various Python objects?  As is, ctrl-c quits my program AND IPython.

There are two options:

1. Use @pdb within ipython.  Any uncaught exception will trigger pdb.  @pdb is 
an on/off toggle (see its docstring for details).

2. Look at the manual for how to (in 2 lines of code) embed ipython into your 
programs: http://ipython.scipy.org/doc/manual/node9.html

By the way, in which platform do you see Ctrl-C quitting IPython?  This should 
definitely NOT be happening.  Which version of ipython are you using?

On my system (Linux, current CVS ipython), all KeyboardInterrupt exceptions 
are caught:

In [1]: cat t.py
print 'hi'

x=raw_input('enter something\n')

print 'x=',x

In [2]: run t
hi
enter something
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)

/home/fperez/t.py
       1 print 'hi'
       2
----> 3 x=raw_input('enter something')
       4
       5 print 'x=',x

KeyboardInterrupt:
WARNING: Failure executing file: <t.py>

In [3]:


... and ipython continues happily.

Regards,

f.



More information about the IPython-user mailing list