[IPython-user] ipython prevents sys.last_traceback (etc.) from being set?

Fernando Perez Fernando.Perez at colorado.edu
Thu Mar 9 23:50:11 CST 2006


Hi,

Zachary Pincus wrote:
> Hi folks,
> 
> I'm trying ipython with a fresh build of python 2.5. Everything seems  
> to work, except that exceptions no longer cause sys.last_traceback  
> (and last_value and last_type) to be set. (This works fine in the  
> normal python shell.)
> 
> This means that pdb.pm(), which uses sys.last_traceback, doesn't work  
> anymore. The magic %pdb works fine, but I usually prefer to manually  
> fire off pdb.pm() when I need it, instead of having it open at every  
> exception. (Aside: is there any way to easily run iPython's enhanced  
> postmortem, but only on-demand, and not automatically like setting % 
> pdb does?)
> 
> It seems that somehow, ipython is preventing sys.last_[traceback|type| 
> value] from being set when an exception happens. The changelog  
> mentions that these values are no longer used in ipython, but I  
> assume that ipython isn't actively preventing them from being set at  
> all?
> 
>>	* IPython/iplib.py (showtraceback): remove use of the
>>	sys.last_{type/value/traceback} structures, which are non
>>	thread-safe.

Well, it's not that ipython tries to block anything, it's that these objects
need to be _manually_ set.  It just so happens that python's default exception
handler sets them, as ipython used to in the past.  But as of this recent
changeset:

http://projects.scipy.org/ipython/ipython/changeset/975#file2

I removed them.  The reason is thread-safety: the python docs explicitly
discourage their use in a threaded context (see 
http://www.python.org/doc/lib/module-traceback.html), and ipython has 
multithreaded support.

So at this point I see two possibilities:

1. If you think there's a thread-safe way of hanling these guys, we'd gladly 
take a patch.

2. If you don't care about thread safety, you can install a custom exception 
handler which sets these in your personal config.  IPython has a 
set_custom_exc function to put in your own exception handler.  You could write 
one which simply sets these variables and then delegates the actual exception 
handling to ipython's own, so you don't really have to write much code at all.


But I'm afraid that I won't revert the patch, since I don't want to risk 
introducing bugs for users of the multithreaded features (which are out there).

I hope this helps some.

Cheers,

f




More information about the IPython-user mailing list