diff options
author | Brett Cannon <brett@python.org> | 2013-11-22 14:53:07 -0500 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-11-22 14:53:07 -0500 |
commit | df38a80abaef73aee7148c28aca4f46de77e40b4 (patch) | |
tree | cc21b9ed066a26735a91bedea74ba1faa3f4869e /Lib/asyncio | |
parent | 224b26125818056f5d38e2806a1c26fd91ab869c (diff) | |
parent | 7a465647e47957e95acc3ae0f84d945b0c47707d (diff) | |
download | cpython-git-df38a80abaef73aee7148c28aca4f46de77e40b4.tar.gz |
merge
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/futures.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py index db278386ea..dd3e718d9a 100644 --- a/Lib/asyncio/futures.py +++ b/Lib/asyncio/futures.py @@ -301,6 +301,8 @@ class Future: The other Future may be a concurrent.futures.Future. """ assert other.done() + if self.cancelled(): + return assert not self.done() if other.cancelled(): self.cancel() @@ -324,14 +326,17 @@ def wrap_future(fut, *, loop=None): """Wrap concurrent.futures.Future object.""" if isinstance(fut, Future): return fut - assert isinstance(fut, concurrent.futures.Future), \ 'concurrent.futures.Future is expected, got {!r}'.format(fut) - if loop is None: loop = events.get_event_loop() - new_future = Future(loop=loop) + + def _check_cancel_other(f): + if f.cancelled(): + fut.cancel() + + new_future.add_done_callback(_check_cancel_other) fut.add_done_callback( lambda future: loop.call_soon_threadsafe( new_future._copy_state, fut)) |