您的位置:首页 > 编程语言 > Python开发

python 创建多个线程并启动

2017-11-09 11:16 288 查看
创建多个线程并启动这些线程          th_num : 15

th_num = conf["crawl_threads"]
self._thread_list = []

self._thread_states = [None,] * th_num
for 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 = True
self._thread_handle.start()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: