Apparent documentation conflict for Future.result?

The docs page for asyncio.run_coroutine_threadsafe offers this example code:

future = asyncio.run_coroutine_threadsafe(coro, loop)

[...more code...]

    result = future.result(timeout)
except concurrent.futures.TimeoutError:
    print('The coroutine took too long, cancelling the task...')
except Exception as exc:
    print(f'The coroutine raised an exception: {exc!r}')
    print(f'The coroutine returned: {result!r}')

I’ve tried this and it works.

There is another part of the docs which seem to be saying this won’t work. Firstly, it says you can’t use a timeout.
On the page for the Future Object I can see Future.result() with no parameters. There is a note marked Important at the foot of the page which says, “asyncio.Future.result() and asyncio.Future.exception() do not accept the timeout argument”.

Secondly, in that same Important footnote it says the exception raised by an unfinished Future is not
concurrent. futures.TimeoutError but asyncio. InvalidStateError.

So either the docs are contradictory or — more likely — I’m missing something. Which and what is it?

What you are missing is that there are two different kinds of Future objects, concurrent.futures.Future and asyncio.Future.

The thing returned by asyncio.run_coroutine_threadsafe is a concurrent.futures.Future as mentioned in the second line there, and concurrent.futures.Future.result does take a timeout parameter.

Thanks Saaket, I see it now. They just kind of snuck it in - without realizing that it might be confusing for anyone new to concurrency.