import threading
def worker(num):
print('Worker %d is running...' % num)
threads = []
for i in range(5):
t = threading.Thread(target=worker, args=(i,))
threads.append(t)
t.start()
# 等待所有线程执行完毕
for t in threads:
t.join()
print('All workers have finished.')
import threading
import time
from PyQt5.QtWidgets import QApplication
def worker():
print("Worker Thread started")
time.sleep(2)
print("Worker Thread ended")
threads = []
for _ in range(5):
t = threading.Thread(target=worker)
threads.append(t)
t.start()
print("Main Thread is executing other operations...")
# 等待所有线程执行完毕
for t in threads:
t.join()
print("Main Thread execution completed.")
# 允许Qt主事件循环处理其他事件
while True:
if not QApplication.processEvents():
break