# Excerpt from http://www.dabeaz.com/coroutines/pyos4.py | |
# coroutine that will be wrapped in a task | |
def foo(): | |
mytid = yield GetTid() | |
... | |
# A system call | |
class GetTid(SystemCall): | |
def handle(self): | |
# The scheduler "injects" task in the | |
# system call | |
self.task.sendval = self.task.tid | |
class Scheduler(object): | |
... | |
def mainloop(self): | |
... | |
# RHS of foo's yied | |
result = task.run() | |
if isinstance(result, SystemCall): | |
result.task = task | |
result.sched = self | |
result.handle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment