Author antoine.pietri
Recipients antoine.pietri, asvetlov, yselivanov
Date 2019-09-28.14:43:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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). I think this pattern is *very* common and could use a higher level interface.

Would an API like this make sense?

async def create_thread(callable, *args, *, kwargs=None, loop=None, timeout=None)

Then it could just be used like this:

await asyncio.create_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:
Date User Action Args
2019-09-28 14:43:05antoine.pietrisetrecipients: + antoine.pietri, asvetlov, yselivanov
2019-09-28 14:43:05antoine.pietrisetmessageid: <>
2019-09-28 14:43:04antoine.pietrilinkissue38306 messages
2019-09-28 14:43:04antoine.pietricreate