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

 

posted on 2019-06-16 22:42  lilyxiaoyy  阅读(823)  评论(0编辑  收藏  举报

返回
顶部