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
[FEATURE] Make event-handling optional #526
Comments
Is that #510 what you'd want? |
Yeah, pretty much. Subclassing |
I'm making a Windows service as well. However, I didn't do anything about the event loop policy as you describe (and yet it seems to work), so I'm wondering whether I am missing some non-obvious problem? What issue did you have that made you go for the workaround with I am running |
@vashek: As mentioned in the OP, it was because of mhammond/pywin32#1452, but disabling |
This should be fixed by #871 without the need to subclass |
I need option to disable installation of signal handlers. I found some workarounds:
As for me the last method is the best of the worst. But why did you refuse a direct solution with option for Config? |
I'm trying to get Uvicorn to run as a Windows service so event logging and automatic start/restart can be handled more cleanly than by just running
uvicorn
as a scheduled task. I've run into a number of roadblocks, though most of these I've been able to work my way around with some configuration. The main roadbloack I still have is event-loop compatibility. Due to some odd behavior of Python threads while running as a windows service (see mhammond/pywin32#1452), it's not currently possible for Python code to register signal handlers. That makes the defaultProactorEventLoop
unusable, but that can be solved by falling back to aSelectorEventLoop
, which used to be the default event loop for Windows before Python 3.8. Not being able to handle the signal for Ctrl+C is not too much of a problem for my use case either, since I can just set the service to trip theServer#should_exit
flag manually when the service is asked to stop.So with all this said and done, if you ignore the service boilerplate wrapping my code, I'm essentially running Uvicorn like this:
The main problem I still have with this is this line, which will try to setup event handlers even though doing so will immediately fail given my event loop configuration:
uvicorn/uvicorn/main.py
Line 360 in 996aa2d
uvicorn/uvicorn/main.py
Lines 518 to 527 in 996aa2d
I currently have to go and comment out that line in the uvicorn module code to get my application to start at all, which is less than ideal. Would it be possible to make signal handling optional if uvicorn is running from inside a Python script, maybe?
EDIT: I would have tried
import uvicorn; uvicorn.main.HANDLED_SIGNALS = ()
, but it turns out thatuvicorn.main:main
is imported byuvicorn
in a way that shadows the realuvicorn.main
package, so even this awful hack is not an option.The text was updated successfully, but these errors were encountered: