在pymongo

时间:2015-05-04 12:39:41

标签: mongodb python-3.x pymongo python-multithreading

我有一个python应用程序,它为作业创建了多个线程。每个线程连接到mongodb并检索数据。允许连接到mongodb的数量是200,我使用信号量进行处理。一旦完成mongo查询工作,每个线程都会关闭mongodb连接。但是在执行此应用程序时,我为所有线程获得了相同的错误。错误是:

Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 921, in _bootstrap_inner
    self.run()
  File "C:\Python34\lib\threading.py", line 869, in run
    self._target(*self._args, **self._kwargs)
  File "C:/path/pytest/under_construction/testAlgo.py", line 95, in sample_thread
    status=monObj.process_status(list_value1,list_value2,5,120,120)
  File "C:\path\pytest\under_construction\mongo_lib.py", line 153, in process_status
    result=self.mongo_result('Submission','find',q={})
  File "C:\path\pytest\under_construction\mongo_lib.py", line 53, in mongo_result
    result=list(_query[query_type.lower()](query_string[keys]))
  File "C:\Python34\lib\site-packages\pymongo\cursor.py", line 1076, in __next__
    if len(self.__data) or self._refresh():
  File "C:\Python34\lib\site-packages\pymongo\cursor.py", line 1037, in _refresh
    limit, self.__id))
  File "C:\Python34\lib\site-packages\pymongo\cursor.py", line 933, in __send_message
    res = client._send_message_with_response(message, **kwargs)
  File "C:\Python34\lib\site-packages\pymongo\mongo_client.py", line 1205, in _send_message_with_response
    response = self.__send_and_receive(message, sock_info)
  File "C:\Python34\lib\site-packages\pymongo\mongo_client.py", line 1182, in __send_and_receive
    return self.__receive_message_on_socket(1, request_id, sock_info)
  File "C:\Python34\lib\site-packages\pymongo\mongo_client.py", line 1174, in __receive_message_on_socket
    return self.__receive_data_on_socket(length - 16, sock_info)
  File "C:\Python34\lib\site-packages\pymongo\mongo_client.py", line 1153, in __receive_data_on_socket
    chunk = sock_info.sock.recv(length)
MemoryError

创建mongo连接的代码

client=MongoClient(mc_name,port)

我在想,这个错误是由于所有线程的结果在运行我的应用程序的机器的一个端口累积造成的吗?

1 个答案:

答案 0 :(得分:1)

MongoClient是一个线程安全的连接池,因此您应该创建一个由所有工作线程共享的单个实例,而不是让每个线程创建自己的。

连接池大小默认为100,但是如果你想让它更大,你可以使用

These 2 lines are the problem [error] error while loading , error in opening zip file [error] object scala.runtime in compiler mirror not found.

From what I understand I have some scalar or mvn package broken before, it causes this error, I have to remove them. Also it may also because of sbt was old that's why I did clean that.

参数来做到这一点(例如 )。