Skip to content

Instantly share code, notes, and snippets.

@oberstet
Created May 28, 2014 06:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save oberstet/4ea003fd8e91dcb9cba3 to your computer and use it in GitHub Desktop.
import inspect
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from autobahn.twisted import util
def foo1():
print("foo1")
return 1
@inlineCallbacks
def foo2():
print("foo2")
yield util.sleep(1)
returnValue(2)
def foo3():
print("foo3")
yield util.sleep(1)
returnValue(3)
@inlineCallbacks
def test():
print("foo1 is a coroutine: {}".format(inspect.isgeneratorfunction(foo1)))
print("foo2 is a coroutine: {}".format(inspect.isgeneratorfunction(foo2)))
print("foo3 is a coroutine: {}".format(inspect.isgeneratorfunction(foo3)))
foo1()
yield foo2()
foo3()
yield foo3()
reactor.stop()
test()
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment