python 创建多个线程并启动

来源:互联网 发布:模拟现场灯光软件 编辑:程序博客网 时间:2024/06/05 08:42


创建多个线程并启动这些线程          th_num : 15

th_num = conf["crawl_threads"]self._thread_list = []self._thread_states = [None,] * th_numfor tid in range(th_num):    th = threading.Thread(target=self.crawl_process, args=(tid,) )    self._thread_list.append(th)    th.start()


判断此线程是否存在,若不存在 则新建并启动线程

if self._thread_handle != None:    raise ValueError, "Loader has already started"self._thread_handle = threading.Thread(target=self._loop_scan, args=())self._scan_flag = Trueself._thread_handle.start()

阅读全文
0 0
原创粉丝点击