i have following code, results in error:
typeerror('smalltask() takes 1 argument (2 given)',)
@task def master(): count = 0 obj = { 'var1':'val1', 'var2':'val2' } while count < 10: subtask('smalltask',obj).apply_async() count += 1 @task(name='smalltask') def smalltask(obj): print obj
passing dictionary function, imagine need use **kwargs if that, error function takes no arguments yet 2 have been supplied.
i assume issue here either decorator (have basic understanding of not enough solve problem) or subtask function in celery.
i don't have enough python knowledge proceed..could give me idea of what's happening , how can pass smalltask function dictionary?
you need pass arguments subtask in args
keyword argument, must tuple according celery.subtask()
documentation:
subtask('smalltask', args=(obj,)).apply_async()
or use task.subtask()
method on smalltask
task, again pass arguments tuple:
smalltask.subtask((obj,)).apply_async()
alternatively, use star arguments task.s()
method:
smalltask.s(obj).apply_async()
the subtasks documentation linked use tuple in examples; arguments , keyword arguments 2 pieces of data celery has store until can run task, then it'll apply arguments , keyword arguments you.
but celery.subtask()
function takes more arguments , keyword arguments task; takes additional options. in order work arbitrary arguments (positional or keyword) task, and support other arguments not passed task, function signature has no choice accept positional arguments explicit tuple, , keyword arguments explicit dictionary.
the task.s()
method not accept arguments other task accept, support passing arguments if called task directly. internally, uses catch-all arguments: task.s(*args, **kwarg)
, , passes captured arguments tuple , dictionary on task.subtask()
.
Comments
Post a Comment