[issue9914] trace/profile conflict with the use of sys.modules[__name__]

Nick Coghlan report at bugs.python.org
Thu Jul 26 10:09:04 CEST 2012


Nick Coghlan <ncoghlan at gmail.com> added the comment:

This is a tricky one. Long term, the right approach is to migrate all the "scripts that run other scripts" over to runpy, but the runpy API needs work before we can do that (see #9325).

For bug fix purposes though, these modules can borrow some of runpy's infrastructure in order to fake the system state correctly. Specifically, the runpy._TempModule and runpy._ModifiedArgv0 context managers. (_TempModule may need a tweak to allow the module to be used to be passed in rather than always being implicitly created)

See runpy._run_module_code for an example of how to use them.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9914>
_______________________________________


More information about the Python-bugs-list mailing list