Reputation: 1993
If I have a class with attributes...
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()
and I want to access the attributes of my class...
In my testing I am not able to access t.variable2 once inside of my celery task... How can I get access to those attributes?
Thanks!
Upvotes: 0
Views: 397
Reputation: 6796
Tasks are executed by a separate worker process, which being in a different process does not have access to the thread where you assigned those values. You need to send the data required by the class you're instantiating inside the task as arguments to the task, and create the instance inside the task as well:
@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'])
Upvotes: 1