Skip to content

Instantly share code, notes, and snippets.

@kunigami
Last active January 31, 2020 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/9a2f840b9ee8b208bc0b79f4d4685b52 to your computer and use it in GitHub Desktop.
Save kunigami/9a2f840b9ee8b208bc0b79f4d4685b52 to your computer and use it in GitHub Desktop.
# 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