下面看个例子
import threading
class mythread(threading.Thread):
event=threading.Event()
event.set()
t1=[]
for i in range(10):
for i in t1:
运行的结果为:
>>>
1
0
3
2
5
4
7
6
9
8
>>>
本文详细介绍了Python中Event对象的使用方法,包括如何设置和清除信号,以及如何利用Event对象实现线程间的通信。通过示例代码演示了Event对象在多线程环境下如何协调线程执行。
下面看个例子
import threading
class mythread(threading.Thread):
event=threading.Event()
event.set()
t1=[]
for i in range(10):
for i in t1:
运行的结果为:
>>>
1
0
3
2
5
4
7
6
9
8
>>>
1231
1723

被折叠的 条评论
为什么被折叠?