Coroutines in Python for Data Engineering (1)
3 min readJan 13, 2021
Coroutine — greenlet
from greenlet import greenlet
def test1():
print("Test1 begins")
gr2.switch()
print("Test1 ends")
def test2():
print("Test2 begins")
gr1.switch()
print("Test2 ends")
gr1 = greenlet(test1)
gr2 = greenlet(test2)
gr1.switch()
Greenlet provides a more straightforward way switch()
to switch between functions, instead of yield,
next
and send
.
In the code above, we created two greenlet object, gr1
and gr2
. gr1
is actually calling test
and gr2
is…