GH-95097: fix asyncio.run for tasks without uncancel method (#95211)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
This commit is contained in:
Kumar Aditya 2022-07-28 21:17:54 +05:30 committed by GitHub
parent bceb197947
commit 54f48844d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 6 deletions

View file

@ -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