python多线程的使用

最近在做爬虫,经常用到多线程。这里总结一下我的多线程的使用习惯,方便取用

1、创建信号量:

mutex=threading.Lock()

2、信号锁与释放

 mutex.acquire()
 #临界区
 mutex.release()

3、多线程创建与启动

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()
原文地址:https://www.cnblogs.com/superxuezhazha/p/6658284.html