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
Handling interruption in async tasks #88927
Comments
The idea is to provide a way for graceful shutdown so that if an interruption occurs all async tasks are given a certain time to finish before we exit the process. Please take a look at the provided example -> https://gist.github.com/IlianIliev/9aba04a74a4faddf0749533205d3b001 If the interruption happens during an await (if we use But if the interruption happens during a normal execution ( This was found while looking for a way to provide a graceful shutdown for the grpcio server -> grpc/grpc#26123 Is it possible to change the behaviour so the exception is raised on a higher level when sync tasks are executed in async context? |
This issue was quite mysterious to me until I followed the link to grpc/grpc#26123. There (towards the end) it is implied that grpc has a feature called "graceful shutdown" which appears to be working by sending a Do I have that right? If that is indeed the problem, the solution might be as simple as running the asyncio event loop in a separate thread, while the main thread just waits forever until a signal arrives. It can then catch the If I didn't understand the problem correctly, could you indicate whether you are still interested in keeping this issue open? |
Hi @gvanrossum, it was quite a surprise to see a response from the Python creator himself, and then you for spending time to look at this. You have correctly understood the problem, and what you proposed is probably going to work, another workaround is wrapping each task in a try/except. What I am trying to understand is why we have this inconsistent behavior between running in async and non-async mode, and whether this is the expected way for the interpreter to behave. |
Yes, this is how it is supposed to work. |
I understand, thank you. I believe you can close the ticket in this case. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: