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 ncoghlan
Recipients belopolsky, eli.bendersky, georg.brandl, ncoghlan, terry.reedy
Date 2010-09-21.21:26:19
SpamBayes Score 2.5499457e-07
Marked as misclassified No
Message-id <1285104381.54.0.821834880277.issue9325@psf.upfronthosting.co.za>
In-reply-to
Content
I've thought about this in the past, but never really pursued it due to the question of what to do with the __main__ namespace.

There are three options here:
1. Use runpy.run_module to run the module in a fresh __main__ namespace
2. Use runpy.run_module to run the module under its own name
3. Use runpy._run_module_as_main to run the module in the real __main__ namespace

Option 3 is probably a bad idea (due to the risk of clobbering globals from pdb/trace/profile/doctest/etc) but failing to do it that way creates a difference between the way the actual -m switch works and what these modules will be doing.

That said, I haven't looked closely at what these modules do for ordinary scripts, where much the same problem will already arise. If option 1 is adequate for this purpose, then it shouldn't be that hard to add - it's just that I've never done the investigation to see if it *would* be adequate.
History
Date User Action Args
2010-09-21 21:26:21ncoghlansetrecipients: + ncoghlan, georg.brandl, terry.reedy, belopolsky, eli.bendersky
2010-09-21 21:26:21ncoghlansetmessageid: <1285104381.54.0.821834880277.issue9325@psf.upfronthosting.co.za>
2010-09-21 21:26:19ncoghlanlinkissue9325 messages
2010-09-21 21:26:19ncoghlancreate