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

pyuwsgi: not reloadable due to binary-path resolving symlinks (?) #2478

Open
asottile-sentry opened this issue Aug 31, 2022 · 0 comments
Open

Comments

@asottile-sentry
Copy link

here is a minimal reproduction:

# app.py

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"]
python3 -m venv venv
venv/bin/pip install pyuwsgi
venv/bin/uwsgi --py-autoreload 1 --http :9001 --wsgi-file app.py

once it is running, edit app.py changing the response to something else and uwsgi will crash:

$ ./venv/bin/uwsgi --py-autoreload 1 --http :9001 --wsgi-file app.py
*** Starting uWSGI 2.0.20 (64bit) on [Wed Aug 31 09:36:22 2022] ***
compiled with version: 8.3.1 20190311 (Red Hat 8.3.1-3) on 11 November 2021 18:14:15
os: Linux-5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022
nodename: asottile-sentry
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 5
current working directory: /tmp
detected binary path: /usr/bin/python3.10
your processes number limit is 31521
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :9001 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:37915 (port auto-assigned) fd 3
Python version: 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
--- Python VM already initialized ---
Python main interpreter initialized at 0x55e1587d1140
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145808 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x55e1587d1140 pid: 7104 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 7104)
spawned uWSGI worker 1 (pid: 7105, cores: 1)
spawned uWSGI http 1 (pid: 7106)
Python auto-reloader enabled
[pid: 7105|app: 0|req: 1/1] 127.0.0.1 () {28 vars in 296 bytes} [Wed Aug 31 09:36:25 2022] GET / => generated 11 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (1 switches on core 0)
[uwsgi-python-reloader] module/file app.py has been modified
gateway "uWSGI http 1" has been buried (pid: 7106)
...gracefully killing workers...
Gracefully killing worker 1 (pid: 7105)...
worker 1 buried after 1 seconds
binary reloading uWSGI...
chdir() to /tmp
closing all non-uwsgi socket fds > 2 (max_fd = 1024)...
found fd 3 mapped to socket 0 (127.0.0.1:37915)
running /usr/bin/python3.10
Traceback (most recent call last):
  File "/tmp/./venv/bin/uwsgi", line 5, in <module>
    from pyuwsgi import run
ModuleNotFoundError: No module named 'pyuwsgi'

I noticed that during the startup it prints this (suspicious) message:

detected binary path: /usr/bin/python3.10

despite my sys.executable being /tmp/venv/bin/python3

$ readlink -f venv/bin/python3
/usr/bin/python3.10

therefore I can work around this by setting --binary-path:

venv/bin/uwsgi --py-autoreload 1 --http :9001 --wsgi-file app.py --binary-path "$PWD/venv/bin/python3"
$ venv/bin/uwsgi --py-autoreload 1 --http :9001 --wsgi-file app.py --binary-path "$PWD/venv/bin/python3"
*** Starting uWSGI 2.0.20 (64bit) on [Wed Aug 31 09:38:27 2022] ***
compiled with version: 8.3.1 20190311 (Red Hat 8.3.1-3) on 11 November 2021 18:14:15
os: Linux-5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022
nodename: asottile-sentry
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 5
current working directory: /tmp
detected binary path: /tmp/venv/bin/python3
your processes number limit is 31521
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :9001 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:44069 (port auto-assigned) fd 3
Python version: 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
--- Python VM already initialized ---
Python main interpreter initialized at 0x5570d1feb560
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145808 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x5570d1feb560 pid: 7164 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 7164)
spawned uWSGI worker 1 (pid: 7165, cores: 1)
spawned uWSGI http 1 (pid: 7166)
Python auto-reloader enabled
[uwsgi-python-reloader] module/file app.py has been modified
gateway "uWSGI http 1" has been buried (pid: 7166)
...gracefully killing workers...
Gracefully killing worker 1 (pid: 7165)...
worker 1 buried after 1 seconds
binary reloading uWSGI...
chdir() to /tmp
closing all non-uwsgi socket fds > 2 (max_fd = 1024)...
found fd 3 mapped to socket 0 (127.0.0.1:44069)
running /tmp/venv/bin/python3
*** Starting uWSGI 2.0.20 (64bit) on [Wed Aug 31 09:38:33 2022] ***
compiled with version: 8.3.1 20190311 (Red Hat 8.3.1-3) on 11 November 2021 18:14:15
os: Linux-5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022
nodename: asottile-sentry
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 5
current working directory: /tmp
detected binary path: /tmp/venv/bin/python3
your processes number limit is 31521
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :9001 fd 5
uwsgi socket 0 bound to TCP address 127.0.0.1:37001 (port auto-assigned) fd 4
Python version: 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
--- Python VM already initialized ---
Python main interpreter initialized at 0x5646b3431560
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145808 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x5646b3431560 pid: 7164 (default app)
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 7164)
spawned uWSGI worker 1 (pid: 7171, cores: 1)
spawned uWSGI http 1 (pid: 7172)
Python auto-reloader enabled
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