support gevent-using apps when workers>2 after #2183 #2796
Unanswered
markjm
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi - thank you so much for this projects, its been great for me to work with!
Below is a reported issue and suggested fix for compatibility with the (not-so-new anymore) multiprocessing work from #2183 and applications which use gevent.
Issue
I have this gist which demonstrated the issue https://gist.github.com/markjm/7d63260afa0012532151c935ca3b1640
Notice when running
uv run demo.py --patch-parent(to simulate a project where gevent monkeypatches are in use), we see an error like:I believe this is due to gevent patching (which makes most multiprocessing/threading primitives cooperative) interacting with
multiprocess.Pipewhich (according to this comment) can not be patched.Note also that we can’t delay monkeypatching into the worker thread because the spawned process inherits a copy of the parent’s
sys.modules+ modulesuvicornimports before getting to user code. These already-imported modules need to be imported after patching, but that is not possible. This can be simulated viauv run demo.py --patch-workerSuggested solution
Instead of ping-ponging with a
multiprocess.Pipe, use asocket.socketpairinstead. Sockets are gevent-patch-supported, so this change in management communication should be enough to ensure any projects like mine to work again after the multiprocessing changes.I have a draft of something which I think has potential viable here main...markjm:uvicorn:markjm/multi-processing
If im in the right track, change seems not-too intrusive to me!
Alternative solutions
TBH I am no expert in this area, so also open to other ideas, suggestions, or you can just tell me this is outside the realm of something youre interested in fixing
Beta Was this translation helpful? Give feedback.
All reactions