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

 

相关文章:

  • 2021-09-10
  • 2021-09-15
  • 2022-12-23
  • 2021-05-23
  • 2021-06-08
  • 2021-12-05
  • 2022-02-06
  • 2021-11-24
猜你喜欢
  • 2022-01-01
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2022-12-23
相关资源
相似解决方案