8000 GH-95097: fix `asyncio.run` for tasks without `uncancel` method by kumaraditya303 · Pull Request #95211 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

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

Merged
merged 7 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
raise CancelledError
  • Loading branch information
kumaraditya303 authored Jul 26, 2022
commit 8e21afa3ea12d61106afe57283f90ef4bfd7bf18
8 changes: 1 addition & 7 deletions Lib/asyncio/runners.py
< D937 td class="blob-num blob-num-deletion empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,7 @@ def run(self, coro, *, context=None):
return self._loop.run_until_complete(task)
except exceptions.CancelledError:
uncancel = getattr(task, "uncancel", None)
if uncancel is None:
def uncancel():
warnings._deprecated('missing asyncio.Task.uncancel',
"Task.uncancel method will be mandatory for task "
"implementations in 3.15", remove=(3, 15))
return 0
if self._interrupt_count > 0 and uncancel() == 0:
if self._interrupt_count > 0 and uncancel and uncancel() == 0:
raise KeyboardInterrupt()
else:
raise # CancelledError
Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_asyncio/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,8 @@ def new_event_loop():
return loop

asyncio.set_event_loop_policy(TestPolicy(new_event_loop))
with self.assertWarns(DeprecationWarning):
with self.assertRaises(KeyboardInterrupt):
asyncio.run(main())
with self.assertRaises(asyncio.CancelledError):
asyncio.run(main())


class RunnerTests(BaseTest):
Expand Down
0