Author Paulo Costa
Recipients Paulo Costa, gvanrossum, vstinner, yselivanov
Date 2016-02-02.22:20:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1454451619.12.0.0280470843365.issue26270@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2016-02-02 22:20:19Paulo Costasetrecipients: + Paulo Costa, gvanrossum, vstinner, yselivanov
2016-02-02 22:20:19Paulo Costasetmessageid: <1454451619.12.0.0280470843365.issue26270@psf.upfronthosting.co.za>
2016-02-02 22:20:19Paulo Costalinkissue26270 messages
2016-02-02 22:20:19Paulo Costacreate