笔者作为一名python职业玩家,仔细研究了下python多线程的使用方法,记录下学习的过程
python中的threading模块是专门用来处理多线程并发的情况,废话少说,直接上代码
import threading
class MyThread(threading.Thread):
def __init__(self, signal):
threading.Thread.__init__(self)
self.signal = signal
def run(self):
print('i am waiting')
self.signal.wait()
print('over')
event = threading.Event()
for i in range(4):
thread = MyThread(event)
thread.start()
if input(': ') == 'True':
event.set()