Most "active" coroutine library project?
tack at urandom.ca
Wed Sep 23 23:40:50 CEST 2009
On Wed, 2009-09-23 at 20:50 +0000, exarkun at twistedmatrix.com wrote:
> immediately outside the generator. This means that you cannot use
> "enhanced generators" to implement an API like this one:
> def doSomeNetworkStuff():
> s = corolib.socket()
> s.connect(('google.com', 80))
> s.sendall('GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n')
> response = s.recv(8192)
> where connect, sendall, and recv don't actually block the entire calling
> thread, they only switch away to another coroutine until the underlying
> operation completes. With "real" coroutines, you can do this.
I might be missing some subtlety of your point, but I've implemented
this functionality using generators in a library called Kaa. In kaa,
your example looks like:
s = kaa.Socket()
yield s.write('GET / HTTP/1.1\nHost: www.google.com\n\n')
response = yield s.read()
Of course, it does require a "coroutine scheduler" be implemented,
which, in kaa, is taken care of by the main loop.
 The curious can visit http://doc.freevo.org/api/kaa/base/ and
http://freevo.org/kaa/ although a 1.0 hasn't yet been released and the
docs are still rather sketchy.
More information about the Python-list