Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class Task(object):
def run(self):
while True:
result =
if isinstance(result, SystemCall):
return result
# sub-routine call
if isinstance(result, types.GeneratorType):
# put the caller on the stack
self.sendval = None = result
if not self.stack:
self.sendval = result
# resume execution to caller = self.stack.pop()
# current coroutine finished
except StopIteration:
# invalid state
if not self.stack:
self.sendval = None = self.stack.pop()
# Example coroutine and sub-coroutine
def Accept(sock):
yield ReadWait(sock)
yield sock.accept()
def server(port):
# ...
while True:
# coroutine that calls another
client, addr = yield Accept(sock)
yield NewTask(handle_client(client, addr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.