Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

I think `asyncio.run_coroutine_threadsafe(coro, loop)` returns a 
concurrent.futures.Future [1] which supports timeout and not asyncio.Future 
which doesn't support timeout. Please add in if I am missing anything. Since 
asyncio docs are being rewritten this would be a great time to contribute too 
if you would like to add more clarification.

Docs at [1] also say the below : 

asyncio.run_coroutine_threadsafe(coro, loop)

    Submit a coroutine to the given event loop. Thread-safe.

    Return a concurrent.futures.Future to wait for the result from another OS 
thread.


```
# bpo33117.py. This needs to be called from a different thread as docs said but 
I am using future.result(timeout) just to make sure there is no error with 
respect to function argument.

import asyncio

loop = asyncio.get_event_loop()
timeout = 4

# Create a coroutine
coro = asyncio.sleep(1, result=3)

# Submit the coroutine to a given loop
future = asyncio.run_coroutine_threadsafe(coro, loop)

# Wait for the result with an optional timeout argument
assert future.result(timeout) == 3
```


➜  cpython git:(master) ./python.exe bpo33117.py
Traceback (most recent call last):
  File "../bpo33117.py", line 13, in <module>
    assert future.result(timeout) == 3
  File 
"/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/concurrent/futures/_base.py",
 line 438, in result
    raise TimeoutError()
concurrent.futures._base.TimeoutError

[1] 
https://docs.python.org/3.8/library/concurrent.futures.html#concurrent.futures.Future



Thanks

----------
nosy: +xtreak

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to