-
Notifications
You must be signed in to change notification settings - Fork 64
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
MultiProcessQueue crashes on KeyboardInterrupt #72
Comments
For the multiprocQueueBase that you are using, I would prefer to leave process-global issues like the handling of KeyboardInterrupt up to the application, since this is a policy decision that could be addressed in multiple different ways depending on the application's preference. For the typical case, I'd recommend a try/finally block in your application:
I believe this should be sufficient to allow a normal Thespian shutdown on a keyboard interrupt. If this is satisfactory, please go ahead and close this issue, but if I've misunderstood or there are additional concerns, please feel free to follow up here. |
I 100% agree that the application should handle the KeyboardInterrupt. That's why I opened this issue. I use thespian behind FastAPI, and my code for startup and shutdown looks something like this: app = FastAPI()
@app.on_event('startup')
def on_startup():
asys = ActorSystem(...)
logger = asys.createActor(..., globalName='logger')
asys.tell(logger, LoggerInitializeMessage(...))
@app.on_event('shutdown')
def on_shutdown():
asys = ActorSystem()
logger = asys.createActor(..., globalName='logger') # never returns.
asys.shutdown() # times out after 10 seconds. ActorExitRequest() never reach the Actors A KeyboardInterrupt triggers FastAPIs shutdown event, but before With the suggested fix |
Sorry, I'm not clear on "With the suggested fix ...". Did you mean the fix I suggested, or the fix you suggested in your original message, and if the latter, where was it that you inserted that fix? Also, can you provide a |
I was referring to the fix I suggested. Here is the thespian.log. I only snipped some file paths:
|
Now with log level DEBUG:
|
Thespian/thespian/system/transport/MultiprocessQueueTransport.py
Lines 211 to 224 in 2341eae
After a
KeyboardInterrupt
it's not possible to get Actors from the actor system or send messages to it, so the system can't be shut down properly any more.Stacktrace
Possible solution:
add
to ignore KeyboardInterrupts and keep the system running, so the thespian user can shut down the system properly. This change worked for me. Not sure if thespian would have to do any other stuff to do in this case or if there is a better place to catch/avoid the Exception.
The text was updated successfully, but these errors were encountered: