python3 greenlet模块

pip install greenlet

# -*- coding: utf-8 -*-
from greenlet import greenlet


def func1():
    print("func1 first")
    gr2.switch()
    print("func2 second")
    gr2.switch()


def func2():
    print("func2 first")
    gr1.switch()
    print("func2 second")


gr1 = greenlet(func1)
gr2 = greenlet(func2)
gr1.switch()

# func1 first
# func2 first
# func2 second
# func2 second

 

上一篇:python学习笔记及作业(函数,内置模块,模块与包)


下一篇:Day03,爬虫的一天