python的这个线程池库感觉不是很好用,用起来的感觉也不怎么好。
# -*- coding: UTF-8 -*-
__docformat__ = "restructuredtext en"
__all__ = [
'makeRequests',
'NoResultsPending',
'NoWorkersAvailable',
'ThreadPool',
'WorkRequest',
'WorkerThread'
]
__author__ = "Christopher Arndt"
__version__ = '1.3.2'
__license__ = "MIT license"
# standard library modules
import sys
import threading
import traceback
try:
import Queue # Python 2
except ImportError:
import queue as Queue # Python 3
# exceptions
class NoResultsPending(Exception):
pass
class NoWorkersAvailable(Exception):
pass
# internal module helper functions
def _handle_thread_exception(request, exc_info):
traceback.print_exception(*exc_info)
# utility functions
def makeRequests(callable_, args_list, callback=None,
exc_callback=_handle_thread_exception):
#制造工作请求
#觉得参数列表定义有点抽象,不怎么好用,
#目前只用过if里传参方式,格式要这样子[((),{}),] 首先外层是列表,每个子项是元祖,每个元组长度必定为2,元组的第一项还是个元组,第二项是字典
requests = []
for item in args_list:
if isinstance(item, tuple):
requests.append(
WorkReques