[New-bugs-announce] [issue24571] [RFE] Add asyncio.blocking_call API

Nick Coghlan report at bugs.python.org
Mon Jul 6 03:36:34 CEST 2015

New submission from Nick Coghlan:

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.

messages: 246342
nosy: giampaolo.rodola, gvanrossum, haypo, ncoghlan, pitrou, yselivanov
priority: normal
severity: normal
stage: needs patch
status: open
title: [RFE] Add asyncio.blocking_call API
type: enhancement
versions: Python 3.5, Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list