系统转移过程中,擅自把aptitude安装的mongoengine换成了pip安装,系统启动以后,报这个错误
报错提示:
File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 748, in _socket_for_reads with self._get_socket(read_preference) as sock_info: File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__ return self.gen.next() File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 712, in _get_socket server = self._get_topology().select_server(selector) File "/usr/local/lib/python2.7/dist-packages/pymongo/topology.py", line 141, in select_server address)) File "/usr/local/lib/python2.7/dist-packages/pymongo/topology.py", line 117, in select_servers self._error_message(selector)) ServerSelectionTimeoutError: No servers found yet
方案一,多传一个connect=False的参数:
MongoClient(uri, connect=False)
def start(uri): time.sleep(2) mclient = MongoClient(uri) mclient.db.collection.find_one() if __name__ == '__main__': p = multiprocessing.Process(target=start, args=('mongodb://localhost:27017/',)) p.start()我的解决方案:虽然我用的不是上面任何方案的接口,我使用的是mongoengine的接口函数,底层任然是pymongo
from mongoengine import connect
按照方案一,在这个connect原调用位置的参数里面加了connect=False,问题解决。
第二个问题,使用新版本pymongo以后出现的问题,错误提示:
[Errno 104] Connection reset by peer
mongodb hard nofile 99999 mongodb soft nofile 99999 mongodb hard nproc 99999 mongodb soft nproc 99999
参考:SoF某贴:http://stackoverflow.com/questions/30710427/pymongo-and-multiprocessing-serverselectiontimeouterror