最近在做爬蟲,經常用到多線程。這裡總結一下我的多線程的使用習慣,友善取用
1、建立信号量:
mutex=threading.Lock()
mutex.acquire()
#臨界區
mutex.release()
for i in range(0,threadNum,1):
tmp_scan=myThread()
tmp_scan.setBar.connect(self.setprocessbar)
tmp_scan.setIp.connect(self.nowip)
tmp_scan.setDaemon(True)
threads.append(tmp_scan)
print len(threads)
for thread in threads:
thread.start()