[Python-ideas] The async API of the future: yield-from

Antoine Pitrou solipsis at pitrou.net
Sun Oct 14 12:40:48 CEST 2012

On Sun, 14 Oct 2012 20:12:04 +1300
Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> So the implementation of sock.async_read() is going
> to have to create another Future to handle waiting
> for the socket to become ready. But then the outer
> Future is an unnecessary complication, because you
> could get the same effect by defining
>     def async_read(self, length):
>        yield future_to_wait_for_fd(self.fd)
>        return os.read(self.fd, length)

read() may fail even if select() returned successfully.
See http://bugs.python.org/issue9090

What this means is that your select-style event loop should probably
also handle actually reading the data. Besides, this will make its API
more easily ported to something like IOCP.



Software development and contracting: http://pro.pitrou.net

More information about the Python-ideas mailing list