I'm in a situation where I would like to refactor some code to use native coroutine functions (aync def) instead of "normal" coroutines that use yield. Most of the code is asnyc, but some of the operations are performed in different threads (using concurrent.futures.Executor).
We have concurrent.futures.Future and asyncio.Future. The former one an be used to execute code in a different thread, the later one can be awaited. Since concurrent.futures.Future does not implement the __await__ method, it cannot be awaited in an ioloop. For example, if I want to read from a file in a different thread, then I can submit that as a task to a ThreadPoolExecutor, but it is not possible to await for it. It is still possible to read from the file in the same thread, but obviously I do not want to do that (because file read can block the loop, and I do not want that). In other words: this makes it impossible to refactor coroutine functions to native coroutine functions. In my concrete use case, coroutines are used in tornado's ioloop, and tornado handles both types of futures *if they are yielded*. But once I switch to async def, yield becomes await and the native await is incompatible with concurrent.futures.Future. Both the await keyword and concurrent.futures.Future are in the standard library. They should be compatible. Is there a reason why concurrent.futures does not implement __await__ ? Thanks, Laszlo -- https://mail.python.org/mailman/listinfo/python-list