Message259438
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 |
|
Date |
User |
Action |
Args |
2016-02-02 22:20:19 | Paulo Costa | set | recipients:
+ Paulo Costa, gvanrossum, vstinner, yselivanov |
2016-02-02 22:20:19 | Paulo Costa | set | messageid: <1454451619.12.0.0280470843365.issue26270@psf.upfronthosting.co.za> |
2016-02-02 22:20:19 | Paulo Costa | link | issue26270 messages |
2016-02-02 22:20:19 | Paulo Costa | create | |
|