我是 python 和线程的新手。我试图一次运行多个线程。这是我的基本代码:
import threading
import time
threads = []
print "hello"
class myThread(threading.Thread):
def __init__(self,i):
threading.Thread.__init__(self)
print "i = ",i
for j in range(0,i):
print "j = ",j
time.sleep(5)
for i in range(1,4):
thread = myThread(i)
thread.start()
Run Code Online (Sandbox Code Playgroud)
当 1 个线程正在等待时,time.sleep(5)我希望启动另一个线程。简而言之,所有线程都应该并行运行。