This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Greg.Slodkowicz
Recipients Greg.Slodkowicz, belopolsky, eli.bendersky, georg.brandl, giampaolo.rodola, ncoghlan, terry.reedy
Date 2011-04-10.21:26:55
SpamBayes Score 3.331307e-10
Marked as misclassified No
Message-id <1302470820.25.0.448483964544.issue9325@psf.upfronthosting.co.za>
In-reply-to
Content
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

?
History
Date User Action Args
2011-04-10 21:27:00Greg.Slodkowiczsetrecipients: + Greg.Slodkowicz, georg.brandl, terry.reedy, ncoghlan, belopolsky, giampaolo.rodola, eli.bendersky
2011-04-10 21:27:00Greg.Slodkowiczsetmessageid: <1302470820.25.0.448483964544.issue9325@psf.upfronthosting.co.za>
2011-04-10 21:26:55Greg.Slodkowiczlinkissue9325 messages
2011-04-10 21:26:55Greg.Slodkowiczcreate