版本:pymongo 3.2.2;python 2.7;mongodb 3.0.12;pathos 0.2a1.dev0
在使用pathos的python多线程/进程库时,遇到了如下错误,注释掉“self.db_userinfo_table = MongoClient('localhost',27017).collection.example”这一行,就可以正常运行,如果不注释数据库初始化这一行,“result = ProcessPool(4).map(r.compute, range(100))”这句就会出错,但数据库还没使用呀,仅仅是初始化,难道pymongo本身有bug,还是pathos有bug?
from pathos.pools import ProcessPool, ThreadPool
import logging
from pymongo import MongoClient
class PMPExample(object):
def __init__(self):
self.cache = {}
self.db_userinfo_table = MongoClient('localhost',27017).collection.example
def compute(self, x):
self.cache[x] = x ** 3
return self.cache[x]
if __name__ == '__main__':
logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
r = PMPExample()
#result = ThreadPool(4).map(r.compute, range(100))
result = ProcessPool(4).map(r.compute, range(100))
log.info("result processpooled caches: {}".format(result))
出现了好多行同样的错误提示: