Message246342
Based on a current python-dev discussion, I'd like to suggest a high level convenience API in asyncio to dispatch a blocking call out to a separate thread or process:
# Call blocking operation from asynchronous code
def blocking_call(f, *args, **kwds):
"""Usage: result = await asyncio.blocking_call(f, *args, **kwds))"""
cb = functools.partial(f, *args, **kwds)
return asyncio.get_event_loop().run_in_executor(cb)
While that function is only a couple of lines long, it's *conceptually* very dense.
The aim would thus be to let folks safely make blocking calls from asyncio code without needing to first understand the intricacies of the event loop, the event loop's executor, or the need to wrap the call in functools.partial. Exploring those would instead become an optional exercise in understanding how asyncio.blocking_call works. |
|
Date |
User |
Action |
Args |
2015-07-06 01:36:34 | ncoghlan | set | recipients:
+ ncoghlan, gvanrossum, pitrou, vstinner, giampaolo.rodola, yselivanov |
2015-07-06 01:36:34 | ncoghlan | set | messageid: <1436146594.33.0.331638937124.issue24571@psf.upfronthosting.co.za> |
2015-07-06 01:36:34 | ncoghlan | link | issue24571 messages |
2015-07-06 01:36:32 | ncoghlan | create | |
|