<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">On Tue, Feb 16, 2016 at 9:00 PM Mike Kaplinskiy <<a href="mailto:mike.kaplinskiy@gmail.com">mike.kaplinskiy@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey folks,<div><br></div><div>I hope this is the right list for this sort of thing (python-ideas seemed more far-fetched).</div><div><br></div><div>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() & pkg_resources.resource_* fail. The root cause is that pex uses runpy.run_module with alter_sys=False. The fix should be to just pass alter_sys=True, but that changes sys.argv[0] and various existing pex files depend on that being the pex file. You can read more at <a href="https://github.com/pantsbuild/pex/pull/211" target="_blank">https://github.com/pantsbuild/pex/pull/211</a> .</div><div><br></div><div>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)`.</div></div></blockquote><div><br></div><div>I don't know enough about pex to really dig into what it is trying to do so this is tangential to answering your question but:</div><div><br></div><div>sys.executable may be None. ex: If you're an embedded Python interpreter there is no Python executable. It cannot be blindly used re-execute the current process.</div><div><br></div><div>sys.argv represents the C main() argv array. Your inclination (in the linked to bug above) to leave sys.argv[0] alone is a good one.</div><div><br></div><div>-gps</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Moreover it might be user-friendly to add a `argv=sys.argv[1:]` argument to set & restore the full arguments to the module, where `argv=None` disables argv[0] switching.</div><div><br></div><div>What do you think?</div><div><br></div><div>Mike.</div><div><br></div></div>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/greg%40krypto.org" rel="noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/greg%40krypto.org</a><br>
</blockquote></div></div>