Это headscratcher ...
У меня есть следующее представление:
def progress_view(request):
result = hello.tasks.my_task.delay(8, request.POST.get('account_name'))
return render(request, 'display_progress.html', {'task_id': result.task_id})
У меня также есть следующее в tasks.py
@shared_task(bind=True)
def my_task(self, seconds, account_name):
progress_recorder = ProgressRecorder(self)
result = 0
pprint(seconds)
pprint(account_name)
for i in range(seconds):
timeline = api.GetUserTimeline(screen_name=account_name,
include_rts=True,
trim_user=True,
exclude_replies=True,
count=2)
time.sleep(1)
result += i
progress_recorder.set_progress(i + 1, seconds)
return result
Вызов:
result = hello.tasks.my_task.delay(8, request.POST.get('account_name'))
дает мне:
TypeError: my_task() takes 2 positional arguments but 3 were given
Полный обратный возврат выглядит следующим образом:
[2020-02-19 15:28:58,951: ERROR/ForkPoolWorker-4] Task
hello.tasks.my_task[5b4f0731-0c48-4bd3-ac5d-8c585a0758c8] raised unexpected:
TypeError('my_task() takes 2 positional arguments but 3 were given',)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/celery.
/app/trace.py", line 382, in trace_task
R = retval = fun(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/celery.
/app/trace.py", line 641, in __protected_call__
return self.run(*args, **kwargs)
TypeError: my_task() takes 2 positional arguments but 3 were given
[2020-02-19 15:29:30,479: ERROR/ForkPoolWorker-6] Task
hello.tasks.my_task[a17c78e5-4835-4a31-a000-d0a0955c91e0] raised unexpected:
TypeError('my_task() takes 2 positional arguments but 3 were given',)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/celery.
/app/trace.py", line 382, in trace_task
R = retval = fun(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/celery. /app/trace.py", line 641, in __protected_call__
return self.run(*args, **kwargs)
TypeError: my_task() takes 2 positional arguments but 3 were given