Open pajod opened 3 weeks ago
what does mean Mixing sys.executable and parsed argv produces unintentional sys.path changes on re-exec:
? Can you provide an example?
Can you provide an example?
python -m gunicorn my:app
is already the simplest and most obvious example. Add print(sys.path, sys.argv, sys.orig_argv)
calls to your (cPython 3.10+) app if you want to see it in action.
Mixing sys.executable and parsed argv produces unintentional sys.path changes on re-exec:
gunicorn my:app
(withargv[0] == '[..]/gunicorn'
)argv[0]
is significant, such aspython3 -m gunicorn my:app
[..]/__main__.py
sys.path
listing directory containing__main__.py
werkzeug
(such asflask
) will crash because we clobbered thehttp
namehttps://github.com/benoitc/gunicorn/blob/903792f152af6a27033d458020923cb2bcb11459/gunicorn/arbiter.py#L68-L76
(Side note: The
p
is wrong and scaring static analyzers, but harmless in cPython. I suggest cleaning it up while we are at it.)https://github.com/benoitc/gunicorn/blob/903792f152af6a27033d458020923cb2bcb11459/gunicorn/arbiter.py#L430-L431
I think we just did not have the option to use the original arguments (added in 3.10):
Objections against just doing just that, on Python versions where we can? Even if we cannot do that for some reason, I would still add a warning when launching with clearly unintended
sys.path
- it is a common source of confusion.