Python 访问方法';调用芹菜任务后的属性
如果我有一个具有属性的类Python 访问方法';调用芹菜任务后的属性,python,celery,Python,Celery,如果我有一个具有属性的类 class Test(object): def __init__(): self.variable='test' self.variable2='' def testmethod(): print self.variable2 t=Test() @celery.task(name="tasks.application") def application(): t.testmethod()
class Test(object):
def __init__():
self.variable='test'
self.variable2=''
def testmethod():
print self.variable2
t=Test()
@celery.task(name="tasks.application")
def application():
t.testmethod()
t.variable2 = '1234'
job = application.apply_async()
我想访问我的类的属性
在我的测试中,我无法在芹菜任务中访问t.variable2一次。。。如何访问这些属性
谢谢 任务由单独的工作进程执行,该工作进程位于不同的进程中,无法访问您分配这些值的线程。您需要将正在任务中实例化的类所需的数据作为参数发送给任务,并在任务中创建实例:
@celery.task(name="tasks.application")
def application(variable, variable2):
t = Test()
t.variable = variable
t.variable2 = variable2
t.testmethod()
job = application.apply_async(['test', '1234'])
您的方法定义缺少自参数,但其余的都可以。您是如何尝试访问类属性的?您收到了什么错误消息?