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

Zachary Pincus zpincus at stanford.edu
Fri Mar 10 13:16:15 CST 2006

Thanks for your exegesis of the issues at play here. It certainly  
looks pretty involved.

> So I'm fully open to revisiting this problem and finding the best  
> possible compromise, but I know it's a bag of thorns.  If we can  
> find a sensible solution (not necessarily perfect), we'll apply  
> it.  But I don't want to do something that makes things worse,  
> which is the frequent outcome of seemingly sensible changes when  
> multithreaded code is in the picture.

Isn't that the truth.

> Part of the problem with threads is that you need to set _several_  
> variables (sys.last_{type,value,traceback}).   It is perfectly  
> possible to get a thread-switch after you've set only some of these  
> and not all.  At that point, I have no idea what a debugger like  
> pdb would do.

I think this may not be a huge issue. Note that pdb.pm() (and other  
interactive things that might want access to sys.last_*) will be  
executed from the interpreter's mainloop. So, if the interpreter is  
in the mainloop, by definition the exception handling has finished.  
Though it might have been interrupted several times, the exception  
handler will have had to finish its business before the mainloop  
starts, right?

All that would seem to be necessary is a way to identify whether the  
current thread is the mainloop thread; if so, then the exception  
handlers should attempt to set the sys.last_* values.

So, can the thread structures be annotated with a '_ipython_mainloop  
= True' type attribute, that could be looked up by the exception  
handlers? Or is introspection on the current thread not possible/ 


More information about the IPython-user mailing list