[New-bugs-announce] [issue26270] Support for read()/write()/select() on asyncio
Paulo Costa
report at bugs.python.org
Tue Feb 2 17:20:19 EST 2016
New submission from Paulo Costa:
I want to read from file descriptors from async coroutines.
I currently use `loop.add_reader(fd, callback)` and `loop.remove_reader(fd)`
It works, but IMO using callbacks feels completely alien in the middle of a coroutine.
I suggest adding new APIs to handle this. e.g.:
- asyncio.select(fd, mode)
- asyncio.read(fd, num)
- asyncio.write(fd, str)
(It would be nice to support all kinds of IO operations, but these are certainly the most important)
Using the current APIs, the async implementation of read() looks like this:
async def async_read(fd. n):
loop = asyncio.get_event_loop()
future = asyncio.Future()
def ready():
future.set_result(os.read(fd, n))
loop.remove_reader(fd)
loop.add_reader(fd, ready)
return future
----------
components: asyncio
messages: 259438
nosy: Paulo Costa, gvanrossum, haypo, yselivanov
priority: normal
severity: normal
status: open
title: Support for read()/write()/select() on asyncio
type: enhancement
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26270>
_______________________________________
More information about the New-bugs-announce
mailing list