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-specified-ambiguously

Any thoughts?

-- 
Antoine Pietri
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/OC43GWDGK6JAQ5QDWW3UC2KKMMXWRLTO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to