Pymongo __getnewargs__ method collection serial object

The Pymongo collection object fails when I try to start my tasks with celery. I guess he could not serialize it. What should I do? By the way, I tried to pickle, but it does not help me.

PS: I do not want to import global db into this module.

Collection cannot be called. If you intended to call the getnewargs method.

The following is sample code. module.py

from celery.contrib.methods import task_method class Some_Class(object): """docstring for Some_Class""" def __init__(self, db): super(Some_Class, self).__init__() self.db = db # This object causes 'Collection' object is not callable #db is a pymongo collection object from db.py @app.task(filter=task_method) # Celery task def add(self): """ db.insert({'some_key':'some_value'}) """ return 3 

db.py

 from pymongo import MongoClient db = MongoClient()['test']['collection'] 
+7
python serialization pymongo pickle celery
source share
1 answer

Are you using this code on a Windows computer? Perhaps there is a problem with the fork base, because the "fork" does not exist on Windows, so the object may not be matched, which causes an error.

0
source share

All Articles