diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-07-29 12:38:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-29 12:38:02 (GMT) |
commit | efeda8b4a1fd8f1c510311c40e46d5fad65512a0 (patch) | |
tree | fd69a9f3c7fd20d380ea5177baf4332844b57a40 /Lib/asyncio/runners.py | |
parent | c26470f0cc900dccf2a7ce4a915fc36596cdf289 (diff) | |
download | cpython-efeda8b4a1fd8f1c510311c40e46d5fad65512a0.zip cpython-efeda8b4a1fd8f1c510311c40e46d5fad65512a0.tar.gz cpython-efeda8b4a1fd8f1c510311c40e46d5fad65512a0.tar.bz2 |
GH-95097: fix `asyncio.run` for tasks without `uncancel` method (GH-95211) (GH-95387)
(cherry picked from commit 54f48844d18bc6fb98849f15a2fc08f92ad240ea)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
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 c58b52e..a19a7f9 100644 --- a/Lib/asyncio/runners.py +++ b/Lib/asyncio/runners.py @@ -119,10 +119,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 |