[Python-Dev] Disabling changing sys.argv[0] with runpy.run_module(...alter_sys=True) (original) (raw)
Brett Cannon brett at python.org
Wed Feb 17 13:44:52 EST 2016
- Previous message (by thread): [Python-Dev] Disabling changing sys.argv[0] with runpy.run_module(...alter_sys=True)
- Next message (by thread): [Python-Dev] Disabling changing sys.argv[0] with runpy.run_module(...alter_sys=True)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, 16 Feb 2016 at 20:59 Mike Kaplinskiy <mike.kaplinskiy at gmail.com> wrote:
Hey folks,
I hope this is the right list for this sort of thing (python-ideas seemed more far-fetched). For some context: there is currently a issue with pex that causes sys.modules lookups to stop working for main. In turns this makes unittest.run() & pkgresources.resource* fail. The root cause is that pex uses runpy.runmodule with altersys=False. The fix should be to just pass altersys=True, but that changes sys.argv[0] and various existing pex files depend on that being the pex file. You can read more at https://github.com/pantsbuild/pex/pull/211 . Conservatively, I'd like to propose adding an argument to disable this behavior. The current behavior breaks a somewhat reasonable invariant that you can restart your program via
os.execv([sys.executable] + sys.argv)
. Moreover it might be user-friendly to add aargv=sys.argv[1:]
argument to set & restore the full arguments to the module, whereargv=None
disables argv[0] switching. What do you think?
This probably is best served as a feature request on bugs.python.org since it's not asking for some massive change or new feature but just a minor tweak to a module. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160217/113437d0/attachment.html>
- Previous message (by thread): [Python-Dev] Disabling changing sys.argv[0] with runpy.run_module(...alter_sys=True)
- Next message (by thread): [Python-Dev] Disabling changing sys.argv[0] with runpy.run_module(...alter_sys=True)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]