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 cause a permission denied error in docker container #350

Open
cooolinx opened this issue Jun 20, 2024 · 2 comments
Open

Hot reload cause a permission denied error in docker container #350

cooolinx opened this issue Jun 20, 2024 · 2 comments

Comments

@cooolinx
Copy link

Hot reload cause a permission denied error in docker container:

Traceback (most recent call last):
  File "/app/z.py", line 9, in <module>
    app.run()
  File "/usr/local/lib/python3.11/site-packages/quart/app.py", line 864, in run
    restart()
  File "/usr/local/lib/python3.11/site-packages/quart/utils.py", line 164, in restart
    os.execv(executable, [executable] + args)
PermissionError: [Errno 13] Permission denied

How to replicate the bug:

  1. Into a docker container docker run --rm -it -v $PWD:/app python:3.11-alpine ash (mount current directory)
  2. Install pip install quart
  3. Create a app.py, code copy from https://pgjones.gitlab.io/quart/tutorials/quickstart.html
  4. Run python /app/app.py
  5. Try to change app.py and you will see the error

When I try to replicate it outside of docker container, hot-reload works fine.

Environment:

  • Python version: 3.11.9
  • Quart version: 0.19.6
@cooolinx
Copy link
Author

cooolinx commented Jun 20, 2024

And then when I tried to look into

def restart() -> None:

The executable was /usr/local/bin/python at the beginning and became /app/app.py at the end.

I noticed that hypercorn condition was incorrectly set to true, which cause the executable variable to change.

def restart() -> None:                                                               
    # Restart  this process (only safe for dev/debug)                                
    executable = sys.executable                                                      
    script_path = Path(sys.argv[0]).resolve()                                        
    args = sys.argv[1:]                                                              
    main_package = sys.modules["__main__"].__package__                               
                                                                                     
    if main_package is None:                                                         
        ...              
        else:                                                            
            if script_path.is_file() and os.access(script_path, os.X_OK):  # <-- HERE!
                # hypercorn run:app --reload                             
                executable = str(script_path)       
            else:                                        
                # python run.py                           
                args = [str(script_path), *args]          
    else:                                                 
        ...
                                                            
    os.execv(executable, [executable] + args)               

@tomfleming
Copy link

I hit this as well, wonder if it may be related to this open docker issue: docker/for-mac#5029

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

2 participants