在python中使用multiprocessing中pool的时候 报错:
Traceback (most recent call last):
File "street_order_data_detail_into_db.1.py", line 500, in <module>
get_result = [res.get() for res in multiple_results]
File "/usr/local/app/anaconda2/lib/python2.7/multiprocessing/pool.py", line 572, in get
raise self._value
cPickle.PicklingError: Can't pickle <type 'NoneType'>: attribute lookup __builtin__.NoneType failed
def task(db):
#do something
if __name__ == "__main__":
db = MySQLdb.connect()
pool = Pool(4)
multiple_results = [pool.apply_async(task,(i,db)) for i in range(10)]
get_result = [res.get() for res in multiple_results]
这时候会报错:
解决方法,将数据库连接操作等 放到任务进程中执行,不要在主进程中传参给任务进程