python 多线程
threads = []
times = 100
for i in range(0,times):
t = threading.Thread(target=connToServer())
threads.append(t)
for i in range(0,times):
threads[i].start()
time.sleep(1)
#for i in range(0,times):
# threads[i].join()
#connToServer()
我的代码是这样的,connToServer()函数里面有个while 1:的循环,为什么这个循环不退出,我的第二个线程就没运行啊?线程不是同步运行的吗
[解决办法]
t = threading.Thread(target=connToServer())
这句红色的括号去掉试试。
[解决办法]
你是想实现线程退出吗?
[解决办法]
import threading
import time
threads = []
times = 100
def connToServer(i):
while(1):
print i
time.sleep(1)
for i in range(0,times):
t = threading.Thread(target = connToServer, args = (i,))
threads.append(t)
for i in range(0,times):
threads[i].start()
time.sleep(1)