diff options
author | Guido van Rossum <guido@python.org> | 2016-09-09 12:54:54 -0700 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2016-09-09 12:54:54 -0700 |
commit | 1140a0342613c30feaedfe96b9e09ad7248de490 (patch) | |
tree | eeb925307793df12b7cb5e3c561a2a3aa152437f /Lib/asyncio/tasks.py | |
parent | c1db513e368eb485df49a4bd354984136f3a39bd (diff) | |
download | cpython-git-1140a0342613c30feaedfe96b9e09ad7248de490.tar.gz |
Rename Future._blocking to _asyncio_future_blocking.
This is now an official "protected" API that can be used to write
classes that are duck-type-compatible with Future without subclassing
it. (For that purpose I also changed isinstance(result, Future) to
check for this attribute instead.)
Hopefully Amber Brown can use this to make Twisted.Deferred compatible
with asyncio.Future.
Tests and docs are TBD.
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r-- | Lib/asyncio/tasks.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 0cca8e36a5..3e200f6338 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -249,7 +249,8 @@ class Task(futures.Future): self.set_exception(exc) raise else: - if isinstance(result, futures.Future): + blocking = getattr(result, '_asyncio_future_blocking', None) + if blocking is not None: # Yielded Future must come from Future.__iter__(). if result._loop is not self._loop: self._loop.call_soon( @@ -257,8 +258,8 @@ class Task(futures.Future): RuntimeError( 'Task {!r} got Future {!r} attached to a ' 'different loop'.format(self, result))) - elif result._blocking: - result._blocking = False + elif blocking: + result._asyncio_future_blocking = False result.add_done_callback(self._wakeup) self._fut_waiter = result if self._must_cancel: |