#!/usr/bin/env python # -*- coding: utf-8 -*- # Software: PyCharm # __author__ == "HAI" # FileName: 协程.py # Date : 2018/10/5 # Time : 11:15 # from greenlet import greenlet # # def func(): # g2.switch() # print(123) # # def eat(): # # print(234) # g1.switch() # # g1 = greenlet(run=func) # # g2 = greenlet(run=eat) # g1.switch() from gevent import monkey; monkey.patch_all() import gevent from time import sleep def func(a,b): print('start func') sleep(1.5) print('end func') return '我是谁' + str(a) + str(b) def func2(): print('start func2') sleep(1.2) print('endfunc2') return 'adfas' g = gevent.spawn(func, 1, 2) b = gevent.spawn(run=func2,) gevent.joinall([ g, b, ]) print(g.value) print(b.value)
协程
最新推荐文章于 2024-09-05 21:15:15 发布