-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
AssertionError on await of Future returned by asyncio.wrap_future #77419
Comments
When the concurrent Future wrapped by asyncio.wrap_future has set_result or set_exception called multiple times, I get the following traceback: Traceback (most recent call last):
File "/usr/local/lib/python3.6/asyncio/events.py", line 145, in _run
self._callback(*self._args)
File "/usr/local/lib/python3.6/asyncio/futures.py", line 399, in _set_state
_copy_future_state(other, future)
File "/usr/local/lib/python3.6/asyncio/futures.py", line 369, in _copy_future_state
assert not dest.done()
AssertionError Minimal reproducible example: import asyncio
import concurrent.futures
f = concurrent.futures.Future()
async_f = asyncio.wrap_future(f)
f.set_result(1)
f.set_result(1)
loop = asyncio.get_event_loop()
loop.run_until_complete(async_f) The documentation says that set_result and set_exception are only meant for Executors, so, arguably using them outside of that context would fall into undocumented behavior rather than a bug. But it still seems like it should be the second set_result that raises something like InvalidStateError. Alternatively, this can be avoided if _copy_future_state checks for done in addition to cancellation. What should happen here? |
May also be worth pointing out that even in the case of only calling set_result once, _done_callbacks still has _chain_future in it: import asyncio
import concurrent.futures
f = concurrent.futures.Future()
async_f = asyncio.wrap_future(f)
f.set_result(1)
loop = asyncio.get_event_loop()
print(loop.run_until_complete(async_f))
print(f._done_callbacks)
Should that be cleared by that point? |
Raising Would you make a pull request? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: