企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] yield实现任务交替执行 ~~~ import time def task_1(): while True: print('---1---') time.sleep(0.1) yield def task_2(): while True: print('---2---') time.sleep(0.1) yield t1 = task_1() t2 = task_2() while True: next(t1) next(t2) ~~~