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 ncoghlan, nedbat, pitrou, serhiy.storchaka
Date 2012-05-15.04:41:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
As Ned notes, to cover *implicit* creation of Python subprocesses an environment based solution would be needed to ensure the subprocesses adopt the desired settings. The advantage that has over the current workarounds is that it can be scoped to only affect the parent process when it is executed rather than affecting an entire Python installation.

As Serhiy notes, for *direct* invocation, you could use a custom module, but that wouldn't help with the subprocess case. In terms of implementation strategy, as with the -m switch, I'd probably bootstrap into runpy as soon as "-C" is encountered anyway to avoid the need for additional complexity in the C code.

One thing that would be useful with this is that it would eliminate some of the demand for -X options, since anything with a Python level API could just use -C instead. To use faulthandler as an example:

Current: "python -Xfaulthandler"
Alternate: "python -C 'import faulthandler; faulthandler.enable()'"

While the second is longer, the advantage is that it's the same as the way you enable faulthandler from Python, so there's no need to learn a special command (and, since its a -X option, the current way doesn't show up in the output of "python --help").

This would also cleanly resolve the request in issue 6958 to allow configuration of the logging module from the command line by allowing you to write things like:

   python -C "import logging; logging.basicConfig()"

The interaction with other logging configuration is obvious (it follows the normal rules for multiple configuration attempts) and doesn't require the invention of new complex rules.

Warnings ends up in a similar boat. Simple options like -Wall, -Wdefault or -Werror are easy to use, but more complex configuration options are tricky. With "-C" you can do whatever you like using the Python API.

Other tricks also become possible without the need for launch scripts, like testing import logic and fallbacks by messing with sys.path and sys.modules, or patching builtins or other modules.
Date User Action Args
2012-05-15 04:41:01ncoghlansetrecipients: + ncoghlan, pitrou, nedbat, serhiy.storchaka
2012-05-15 04:41:01ncoghlansetmessageid: <>
2012-05-15 04:41:00ncoghlanlinkissue14803 messages
2012-05-15 04:41:00ncoghlancreate