[issue14803] Add feature to allow code execution prior to __main__ invocation

Nick Coghlan report at bugs.python.org
Sun Jul 29 14:37:21 CEST 2012


Nick Coghlan added the comment:

Nothing too complicated - just noting that a test suite like ours that launches Python subprocesses to test process global state handling could fairly easily arrange to pass appropriate -C options to trigger things like recording coverage data or profiling options.

I'll also note that if you put a "preinit.py" on sys.path (e.g. in the current directory if using -m for invocation), you could easily do "-C 'import preinit'" to do arbitrarily complex custom setups, including preconfiguring your test framework.

A lot of my thoughts on this come out of looking into migrating the various stdlib modules like trace, pdb and profile over to supporting everything that runpy (and hence the main executable) supports, and a lot of the complexity lies in the mechanics of how to daisy chain the two "__main__" modules together. Running a bit of extra code in __main__ as supplied on the command line before kicking off the full import process helps avoid a lot of pain.

----------

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


More information about the Python-bugs-list mailing list