pymongo集合对象序列化\uu getnewargs\uuu方法

2024-04-25 18:01:49 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试用芹菜运行任务时,Pymongo集合对象失败。我想它不能序列化。我该怎么办?顺便说一句,我试过泡菜,但没用。在

PS:我不想把全局数据库导入这个模块。在

“Collection”对象不可调用。如果你的意思是调用new方法。。。。在

示例代码如下。 模块.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

数据库

^{pr2}$

Tags: 模块对象frompyself数据库taskdb