mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
gh-134173: optimize state transfer between concurrent.futures.Future
and asyncio.Future
(#134174)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
f2de1e6861
commit
53da1e8c8c
5 changed files with 148 additions and 14 deletions
|
@ -351,22 +351,19 @@ def _set_concurrent_future_state(concurrent, source):
|
|||
def _copy_future_state(source, dest):
|
||||
"""Internal helper to copy state from another Future.
|
||||
|
||||
The other Future may be a concurrent.futures.Future.
|
||||
The other Future must be a concurrent.futures.Future.
|
||||
"""
|
||||
assert source.done()
|
||||
if dest.cancelled():
|
||||
return
|
||||
assert not dest.done()
|
||||
if source.cancelled():
|
||||
done, cancelled, result, exception = source._get_snapshot()
|
||||
assert done
|
||||
if cancelled:
|
||||
dest.cancel()
|
||||
elif exception is not None:
|
||||
dest.set_exception(_convert_future_exc(exception))
|
||||
else:
|
||||
exception = source.exception()
|
||||
if exception is not None:
|
||||
dest.set_exception(_convert_future_exc(exception))
|
||||
else:
|
||||
result = source.result()
|
||||
dest.set_result(result)
|
||||
|
||||
dest.set_result(result)
|
||||
|
||||
def _chain_future(source, destination):
|
||||
"""Chain two futures so that when one completes, so does the other.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue