You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Uvicorn has a built-in process manager, so I can run it with, for example, --workers 4 to get 4 worker processes. Uvicorn will run 4 child processes listening on the same port, and will automatically restart processes that die or get stuck. However, if I use --workers 1, Uvicorn will not use its process manager and will instead run the ASGI application directly in the main process.
I have a use case where I only need one worker process, but I need to monitor and restart it on failures. I can use an external process manager like gunicorn or supervisor, but it seems unfortunate to introduce another dependency when everything I need is already supported by Uvicorn itself. The built-in process manager can already run with just one worker by starting with --workers 2 and then sending SIGTTOU. Alternatively, I can copy code form main.py and use Multiprocess directly. However, both of these options seem hacky.
I propose that running Uvicorn with --workers 1 runs the application in a subprocess using Multiprocess process manager. This is both a useful feature and seems more intuitive. Happy to open a PR.
This will also address the issue discussed here: #2390
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Uvicorn has a built-in process manager, so I can run it with, for example,
--workers 4to get 4 worker processes. Uvicorn will run 4 child processes listening on the same port, and will automatically restart processes that die or get stuck. However, if I use--workers 1, Uvicorn will not use its process manager and will instead run the ASGI application directly in the main process.I have a use case where I only need one worker process, but I need to monitor and restart it on failures. I can use an external process manager like
gunicornorsupervisor, but it seems unfortunate to introduce another dependency when everything I need is already supported by Uvicorn itself. The built-in process manager can already run with just one worker by starting with--workers 2and then sendingSIGTTOU. Alternatively, I can copy code formmain.pyand useMultiprocessdirectly. However, both of these options seem hacky.I propose that running Uvicorn with
--workers 1runs the application in a subprocess usingMultiprocessprocess manager. This is both a useful feature and seems more intuitive. Happy to open a PR.This will also address the issue discussed here: #2390
Beta Was this translation helpful? Give feedback.
All reactions