2014-07-09 15 views
5

usando il codice seguente provoca:oggetto 'Collection' non è l'errore richiamabile in pymongo con le procedure piscina

'Collection' object is not callable. If you meant to call the '__getnewargs__' method on a 'Collection' object it is failing because no such method exists. 

Il codice: da multiprocessing importazione Pool db = MongoClient (ip, port)

def f(cursor, arg): 
    for doc in cursor: 
     ... 

p = Pool(4) 
for arg in args: 
    cursor = db[dbName][collName].find() 
    p.apply_async(f,[cursor, arg]) 

db.close() 

Impossibile capire qual è il problema e come eseguire il debug del codice.

completa Traceback:

Exception in thread Thread-2: 
Traceback (most recent call last): 
    File "C:\Python27\lib\threading.py", line 808, in __bootstrap_inner 
    self.run() 
    File "C:\Python27\lib\threading.py", line 761, in run 
    self.__target(*self.__args, **self.__kwargs) 
    File "C:\Python27\lib\multiprocessing\pool.py", line 342, in _handle_tasks 
    put(task) 
    File "C:\Python27\lib\site-packages\pymongo\collection.py", line 1489, in __call__ 
    self.__name.split(".")[-1]) 
TypeError: 'Collection' object is not callable. If you meant to call the '__getnewargs__' method on a 'Collection' object it is failing because no such method exists. 
+1

A quale linea si verifica l'errore? –

+0

aggiornato con traceback completo – user1264304

+0

'Pool' è stato importato dal pacchetto' multiprocessing' di livello superiore o da qualche altro modulo (come 'multiprocessing.dummy 'o qualcosa in pymongo)? – Blckknght

risposta

1

Hai un problema nel vostro uso di cursor. Il metodo Collection.find restituisce un oggetto Cursor che è un materiale di consumo. (http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.Cursor.getitem) Non so se questa è la causa dell'eccezione, ma è sicuramente un problema.

Due soluzioni per voi:

  1. esplicitamente tirare i documenti prima di infilare con un [:] o list
  2. Dare il cursore nella apply_async e clonare il cursore usando clone metodo (http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.Cursor.clone)
Problemi correlati