aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/asyncio/tasks.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2022-04-01 04:25:15 +0300
committerGitHub <noreply@github.com>2022-04-01 04:25:15 +0300
commitd4bb38f82bf18b00db3129031ce4969b6f0caab9 (patch)
treeafdf80168076e324404d2ce492b5a222868b4d19 /Lib/asyncio/tasks.py
parentab89ccff3ca6efc2a8e6f5f45c30d568fb3d212f (diff)
downloadcpython-d4bb38f82bf18b00db3129031ce4969b6f0caab9.tar.gz
cpython-d4bb38f82bf18b00db3129031ce4969b6f0caab9.zip
bpo-47167: Allow overriding a future compliance check in asyncio.Task (GH-32197)
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r--Lib/asyncio/tasks.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 27fe58da151..3952b5f2a77 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -252,6 +252,10 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
self._num_cancels_requested -= 1
return self._num_cancels_requested
+ def _check_future(self, future):
+ """Return False if task and future loops are not compatible."""
+ return futures._get_loop(future) is self._loop
+
def __step(self, exc=None):
if self.done():
raise exceptions.InvalidStateError(
@@ -292,7 +296,7 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
blocking = getattr(result, '_asyncio_future_blocking', None)
if blocking is not None:
# Yielded Future must come from Future.__iter__().
- if futures._get_loop(result) is not self._loop:
+ if not self._check_future(result):
new_exc = RuntimeError(
f'Task {self!r} got Future '
f'{result!r} attached to a different loop')