Skip to content

Instantly share code, notes, and snippets.

@simplyvikram
Last active December 22, 2015 20:59
Show Gist options
  • Save simplyvikram/6529944 to your computer and use it in GitHub Desktop.
Save simplyvikram/6529944 to your computer and use it in GitHub Desktop.
greenlet
from greenlet import greenlet
print "\n\nSwitching between greenlets"
def test1():
print "In test 1 - a"
gr3.switch()
print "In test 1 - b"
gr2.switch()
def test2():
print "In test 2 - a"
gr3.switch()
print "In test 2 - b"
def test3():
print "In test 3 - a"
g_self = greenlet.getcurrent()
g_self.parent.switch()
print "In test 3 - b"
gr2.switch()
gr1 = greenlet(test1)
gr2 = greenlet(test2)
gr3 = greenlet(test3)
gr1.switch()
print "In parent 1"
gr1.switch()
print "In parent 2"
######################################
print "\n\nPassing values between greenlets"
def test_1(x, y):
z = gr_2.switch(x+y)
print z
def test_2(u):
print u
gr_1.switch(42)
gr_1 = greenlet(test_1)
gr_2 = greenlet(test_2)
gr_1.switch("hello", " world")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment