New submission from Jason Haydaman <>:

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/", line 145, in _run
  File "/usr/local/lib/python3.6/asyncio/", line 399, in _set_state
    _copy_future_state(other, future)
  File "/usr/local/lib/python3.6/asyncio/", line 369, in 
    assert not dest.done()

Minimal reproducible example:

import asyncio
import concurrent.futures

f = concurrent.futures.Future()
async_f = asyncio.wrap_future(f)

loop = asyncio.get_event_loop()

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?

components: Library (Lib), asyncio
messages: 315030
nosy: Jason Haydaman, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: AssertionError on await of Future returned by asyncio.wrap_future
versions: Python 3.6

Python tracker <>
Python-bugs-list mailing list

Reply via email to