py3中使用进程池multiprocessing.Pool传入实例化对象作为参数后异常

在py3中使用multiprocessing.Pool创建了进程池.
问题是代码没有报错,进程内部不执行.
多次测试后发现是因为在User在实例化的过程中self初始化包含了其他对象.
实际的对象中比较复杂,不太好把所有的实例化时候绑定到self上的对象拆出来.有什么好的解决方法吗?
非常感谢.
下面的代码可以复现异常,self.http换成其他对象也一样会出问题.
import multiprocessingimport requests
class User:
    def __init__(self, name, pwd):
        self.name = name
        self.pwd = pwd
        # 导致异常点
        self.http = requests
    def __str__(self):
        return f'name:{self.name};pwd:{self.pwd};'
def workFlow(user: User):
    print(user)
def test(userList):
    pool = multiprocessing.Pool(processes=10)
    for item in userList:
        pool.apply_async(workFlow, (item,))
    pool.close()
    pool.join()
if __name__ == '__main__':
    ul = []
    for i in range(10):
        ul.append(User(i, i + 100))
    test(ul)
以上是 py3中使用进程池multiprocessing.Pool传入实例化对象作为参数后异常 的全部内容, 来源链接: utcz.com/p/938181.html

