Message353456
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:
https://stackoverflow.com/questions/54263558/is-asyncio-run-in-executor-specified-ambiguously |
|
Date |
User |
Action |
Args |
2019-09-28 14:43:05 | antoine.pietri | set | recipients:
+ antoine.pietri, asvetlov, yselivanov |
2019-09-28 14:43:05 | antoine.pietri | set | messageid: <1569681785.01.0.799144749415.issue38306@roundup.psfhosted.org> |
2019-09-28 14:43:04 | antoine.pietri | link | issue38306 messages |
2019-09-28 14:43:04 | antoine.pietri | create | |
|