New submission from Ilian Iliev <il...@ilian.io>:

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 `await 
asyncio.sleep(5)`), all works correctly. The exception is raised to the root 
level and we do the graceful shutdown on line 37.

But if the interruption happens during a normal execution (`time.sleep()`) it 
is raised at the currently running line and this way breaks the function 
without any chances or recovery. 
While `time.sleep` is not that widely used, the same problem occurs if we have 
any other long-running code e.g. iterating over a big list.

This was found while looking for a way to provide a graceful shutdown for the 
grpcio server -> https://github.com/grpc/grpc/issues/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?

----------
hgrepos: 407
messages: 398400
nosy: ilian
priority: normal
severity: normal
status: open
title: Handling interruption in async tasks
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44764>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to