fix broken sys.argv list#2777
Conversation
|
The reloader in Werkzeug adds in |
|
@davidism as far as I can see this is broken with or without the reloader. Example app: import sys
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
print(sys.argv)
return 'hello'If you run it with In general this isn't a problem because most apps do not need to use |
|
There is also pallets/werkzeug#531 (also by @miguelgrinberg) and pallets/werkzeug#1242. I feel like I don't understand clearly why Flask and Werkzeug are manipulating |
|
@miguelgrinberg (or anyone) could you comment on how the issues I linked above are related to this? I'm willing to merge one or more of these as soon as I understand where the fix should happen. |
|
My understanding is that these issues come from the fact the when you start your application with "python -m module", Python does some unexpected changes to pallets/werkzeug#531 is an enhancement to Werkzeug that adds the lazy loading of the WSGI app, like Flask does, and it fixes This PR however, tries to make sure that In my opinion these two issues are completely unrelated, and just share the fact that both try to compensate for the way Python handles the |
|
One thing I remember taking a look at was that on Windows, the |
|
I'm not sure this PR will handle that any better than it is currently handled, I wasn't even aware of this difference on Windows. I'll test on a Windows machine tonight and report back. |
The
cli.main()function captures the command-line arguments, and then attempts to change the arguments in thesys.argvlist fromflask ...topython -m flask .... The problem is that it misses thesys,argv[0]element, so the modified argument list begins with-min the 0th element.I honestly don't remember why
sys.argvneeds to be changed to thepython -mform, but I assume there is a good reason for that, so this change addssys.executableas the first argument.