High level interface for loop.run_in_executor?
Hi, I noticed that in 3.7 a lot of high level functions have been added to the asyncio API, but nothing to start blocking functions as non-blocking threads. You still have to call get_event_loop() then await loop.run_in_executor(None, callable). Would an API like this make sense? async def run_thread(callable, *args, *, loop=None, executor=None, timeout=None) Then it could just be used like this: await asyncio.run_thread(my_blocking_read, 4096, timeout=10) This API could wrap the run_in_executor in an asyncio.Task, that way you wouldn't have to await it to start the thread. There's evidence that this has confused people in the past: https://stackoverflow.com/questions/54263558/is-asyncio-run-in-executor-spec... Any thoughts? -- Antoine Pietri
Rereading that, I think maybe create_thread() might make more sense, as it would be analog to create_task() with a similar behavior. Cheers, -- Antoine Pietri
participants (1)
-
Antoine Pietri