diff options
author | Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> | 2022-07-28 15:47:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-28 15:47:54 (GMT) |
commit | 54f48844d18bc6fb98849f15a2fc08f92ad240ea (patch) | |
tree | 203de211ae283397c8bc92c182e6bee42aeab3e6 /Lib/asyncio/runners.py | |
parent | bceb197947bbaebb11e01195bdce4f240fdf9332 (diff) | |
download | cpython-54f48844d18bc6fb98849f15a2fc08f92ad240ea.zip cpython-54f48844d18bc6fb98849f15a2fc08f92ad240ea.tar.gz cpython-54f48844d18bc6fb98849f15a2fc08f92ad240ea.tar.bz2 |
GH-95097: fix `asyncio.run` for tasks without `uncancel` method (#95211)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Diffstat (limited to 'Lib/asyncio/runners.py')
-rw-r--r-- | Lib/asyncio/runners.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Lib/asyncio/runners.py b/Lib/asyncio/runners.py index 7489a50..a8b74d5 100644 --- a/Lib/asyncio/runners.py +++ b/Lib/asyncio/runners.py @@ -118,10 +118,11 @@ class Runner: events.set_event_loop(self._loop) return self._loop.run_until_complete(task) except exceptions.CancelledError: - if self._interrupt_count > 0 and task.uncancel() == 0: - raise KeyboardInterrupt() - else: - raise # CancelledError + if self._interrupt_count > 0: + uncancel = getattr(task, "uncancel", None) + if uncancel is not None and uncancel() == 0: + raise KeyboardInterrupt() + raise # CancelledError finally: if (sigint_handler is not None and signal.getsignal(signal.SIGINT) is sigint_handler |