Skip to content

Instantly share code, notes, and snippets.

@fabiokung
Created December 22, 2011 20:31
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 fabiokung/1511736 to your computer and use it in GitHub Desktop.
Save fabiokung/1511736 to your computer and use it in GitHub Desktop.
generators as fibers
# python 2.7.x
class Fiber:
def __init__(self, callback):
self._callback = callback()
def resume(self):
return self._callback.next()
def work():
yield 1
yield 2
f = Fiber(work)
print f.resume()
print f.resume()
# PS1: almost same API as http://ruby-doc.org/core/Fiber.html
# PS2: http://www.python.org/dev/peps/pep-0342/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment