Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reload not working when app.py has +x permissions #406

Open
Dustella opened this issue Feb 11, 2025 · 2 comments
Open

Hot reload not working when app.py has +x permissions #406

Dustella opened this issue Feb 11, 2025 · 2 comments

Comments

@Dustella
Copy link

Hot reload not working when app.py has +x permissions.

To replicate, create app.py like this, run it in debug mode

from quart import Quart

app = Quart(__name__)


@app.route("/api")
async def json():
    return {"hello": "world"}

if __name__ == "__main__":
    app.run(debug=True)

and give this file +x permissions on Linux

chmod +x app.py

use python app.py to run the code. Saving the file will cause an error like this:

[2025-02-11 13:31:59 +0800] [10620] [INFO] Running on http://127.0.0.1:5000 (CTRL + C to quit)
Traceback (most recent call last):
  File "/home/user/Code/quart_example/./app.py", line 11, in <module>
    app.run(debug=True)
  File "/home/user/miniconda3/lib/python3.11/site-packages/quart/app.py", line 890, in run
    restart()
  File "/home/user/miniconda3/lib/python3.11/site-packages/quart/utils.py", line 170, in restart
    os.execv(executable, [executable] + args)
OSError: [Errno 8] Exec format error

But by running the code using quart run, hot reload will work fine.

Environment:

  • Python version: Python 3.11.11 (main, Dec 11 2024, 16:28:39) [GCC 11.2.0] on linux
  • Quart version: Quart 0.20.0
@Dustella
Copy link
Author

After some digging, I found the error is from

if script_path.is_file() and os.access(script_path, os.X_OK):

why? I know we want to know whether I am ran via quart ... or python xxx.py, but it seems it doesn't even matter, just rerun the executable with args will do good. dealing with xxx.exe is a Windows specific problem, and there is no need to know how it is booted in linux.

@Dustella
Copy link
Author

after some testing, altering

if script_path.is_file() and os.access(script_path, os.X_OK):

        else:
-            if script_path.is_file() and os.access(script_path, os.X_OK):
-                # hypercorn run:app --reload
-                executable = str(script_path)
-            else:
-                # python run.py
-                args = [str(script_path), *args]
+           args = [str(script_path), *args]

will resolve this issue on linux, hot reloading working both with quart run and python xxx.py. Please let me know if someone tested on Mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant