Question about the 'code' module

Fernando Perez at
Fri Dec 30 00:25:38 CET 2005

Thomas Heller wrote:

> I'm using the code module to implement an interactive interpreter
> console in a GUI application, the interpreter running in a separate
> thread.  To provide clean shutdown of the application, I have to make
> sure that objects used in the interpreter thread are deleted when the
> thread ends.
> I delete the sys.last_type, sys.last_value, and sys.last_traceback
> attributes which are set when an exception occured in the interpreter
> thread (*).  To clean up the '_' symbol that the interpreter maintains,
> I have found no other solution than to execute 'console.runsource("0")'
> at the end of the thread.  Where is this symbol stored? How can I delete
> it without the .runsource() call?

Wild guess: try defining your own sys.displayhook to manage output.  This may be
done there, though I'm not really sure.  Otherwise, it's done by the
interpreter internally when exec is called on a code object compiled in
'single' mode.



More information about the Python-list mailing list