Last active
January 31, 2020 06:46
-
-
Save kunigami/9a2f840b9ee8b208bc0b79f4d4685b52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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