版本: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))
出現了很多行相同的錯誤提示: