Greg Słodkowicz <jerg...@gmail.com> added the comment:

Following Nick's advice, I extended runpy.run_module to accept an extra 
parameter to be used as replacement __main__ namespace.

Having this, I can make this temporary __main__ accessible in main() in modules 
like trace/profile/pdb even if module execution fails with an exception. The 
problem is that it's visible only in the calling function but not in the global 
namespace. One way to make it accessible for post mortem debugging would be to 
create the replacement __main__ module in the global namespace and then pass as 
a parameter to main(), but this seems clumsy.

So maybe the way to go is to have runpy store last used __main__, 
sys.exc_info() style. In this case, would this be the correct way to store it 
in runpy:

try:
    import threading
except ImportError:
    temp_main = None
else:
    local_storage = threading.local()
    local_storage.temp_main = None
    temp_main = local_storage.temp_main

?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9325>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to