Python 3.x Python-多处理池映射返回can';t pickle错误

Python 3.x Python-多处理池映射返回can';t pickle错误,python-3.x,multiprocessing,Python 3.x,Multiprocessing,我有以下代码创建testrail客户端并执行testrail的GET_SUITES API调用 我有一个调用GET_SUITES API的函数,我将testrail客户端和test_rail项目id作为参数传递 我正在尝试使用多处理来执行我的项目列表,以加快速度,我不能pickle错误 我的代码: from itertools import product def get_suites(client, project_id): try: path = 'get_suit

我有以下代码创建testrail客户端并执行testrail的GET_SUITES API调用

我有一个调用GET_SUITES API的函数,我将testrail客户端和test_rail项目id作为参数传递

我正在尝试使用多处理来执行我的项目列表,以加快速度,我不能pickle错误

我的代码:

from itertools import product

def get_suites(client, project_id):
    try:
        path = 'get_suites/{projectid}'.format(projectid=project_id)
        test_rail_response = client.send_get(path)
        return test_rail_response
    except Exception as e:
        raise Exception(str(e))

if __name__ == "__main__":
    testRailClient = APIClient(TESTRAIL_URL)
    pool = Pool(2)
    all_project_ids = [100, 200, 300]
    data = pool.starmap(get_suites, product([testRailClient], all_project_ids))
错误堆栈:

Traceback (most recent call last):
  File "main.py", line 57, in <module>
    data = pool.starmap(testrailapi.get_suites, product([testRailClient], all_project_ids))
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/pool.py", line 274, in starmap
    return self._map_async(func, iterable, starmapstar, chunksize).get()
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/pool.py", line 644, in get
    raise self._value
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/pool.py", line 424, in _handle_tasks
    put(task)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/connection.py", line 206, in send
    self._send_bytes(_ForkingPickler.dumps(obj))
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
TypeError: can't pickle SSLContext objects

无需详细说明:重写函数
get_suites
,使其接受URL而不是ApicClient,并在内部构造客户端。嗨,当我将get_suites作为一个独立函数时,它可以工作,但当我将get_suites作为一个方法移动时,它会出现相同的错误
class TestRailExecution:

    def __init__(self, url, username, password):
        self.url = url
        self.username = username
        self.password = password
        self.client = APIClient(self.url)
        self.client.user = username
        self.client.password = password

    def get_suites(self, project_id):
        try:
            path = 'get_suites/{projectid}'.format(projectid=project_id)
            test_rail_response = self.client.send_get(path)
            return test_rail_response
        except Exception as e:
            raise Exception(str(e))

if __name__ == "__main__":
    testRailClient = TestRailExecution(TESTRAIL_URL, user, password)
    pool = Pool(2)
    data = pool.map(get_suites, [100, 200, 300])