On 08:16 pm, sajmik...@gmail.com wrote:
On Wed, Sep 23, 2009 at 2:05 PM,  <exar...@twistedmatrix.com> wrote:
[snip]

But what some Python programmers call coroutines aren't really the same as
what the programming community at large would call a coroutine.

Jean-Paul

Really?  I'm curious as to the differences.  (I just skimmed the entry
for coroutines in Wikipedia and PEP 342, but I'm not fully
enlightened.)

The important difference is that coroutines can switch across multiple stack frames. Python's "enhanced generators" can still only switch across one stack frame - ie, from inside the generator to the frame 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.

Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to