[IPython-user] Re: Auto-discard notification

Fernando Perez fperez at colorado.edu
Thu Dec 18 13:42:28 CST 2003


Maciej Kalisiak wrote:

>>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. 
> 
> 
> Ahhhhhhh.  So if foo.py imports bar.py, and I have edited bar.py, then
> the next invocation of foo.py will still use old copy of bar.py.  Hmm, I
> guess that makes sense, with Python's handling of modules (AFAI
> understand it).

That's exactly the problem.  @dreload goes a long way to help here, but it's 
not perfect.


>>>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).
> 
> 
> I believe this is what I always use... exceptions thrown by my progs get
> nicely caught and I get dropped into pdb.  Hence my hunting around for
> how to make Ctrl-C do the same, seeing as that should be just a
> KeyboardException.
> 
> 
>>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?
> 
> 
> This is on Linux (Debian, 2.4.*).  latest Python 2.3.  IPython 2.3.3c1,
> although I think I've seen this in prior versions too.  Of note might be
> that my app uses wxPython, which may override a lot of things in a
> heavy-handed way.  Still, at worst it should just catch the exception
> and swallow it, not cause a full exit...   Odd.


Well, it definitely works ok for me with a very simple test.  Try this one 
yourself to see what you get:

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

y=1
x=raw_input('enter something\n')

print 'x=',x

In [2]: pdb
Automatic pdb calling has been turned ON

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

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

KeyboardInterrupt:
 > /home/fperez/t.py(4)?()
-> x=raw_input('enter something\n')
(Pdb) print y
1
(Pdb) q
WARNING: Failure executing file: <t.py>

> I'm thinking I might have some Ctrl-C handling in my code somewhere, not
> sure in what form (and unlikely, but possible), but even so, am I
> correct in assuming that the program running inside IPython should not
> have a way of making IPython exit?

Your assumption is correct.  But since you mentioned wxpython, all bets are 
off :)  Wxpython is always very tricky to deal with, so it may well be the 
culprit.

Good luck

f



More information about the IPython-user mailing list