python – How do I start Celery correctly? I get TypeError: 'TaskRegistry' object is not callable

Question:

Hello! I am just mastering the web after switching from the desktop. It is necessary to implement background execution of tasks, for which I chose Celery. The project itself is on the Django framework, but for now I want to try purely Celery.

What I did: – installed celery in virtual environment – installed rabbitmq – created a separate folder in which the tasks.py and celery.py file

Content of tasks.py

from celery import Celery
app = Celery('tasks', backend='amqp', broker='amqp://')
@app.tasks
def print_hello():
print ("Hello")

The content of celery.py (what I found on the Internet, like configs)

from __future__ import absolute_import, unicode_literals
from celery import Celery
app = Celery('proj',
broker='amqp://',
backend='amqp://',
include=['proj.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
result_expires=3600,
)
if __name__ == '__main__':
app.start()

I run it like this: (ENV) root @ cs53546: / home / analytics / messages # celery worker -A tasks

I get this:

Traceback (most recent call last):
File "/home/analytics/ENV/bin/celery", line 11, in 
sys.exit(main())
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/__main__.py", line 14, in main
_main()
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/celery.py", line 326, in main
cmd.execute_from_commandline(argv)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/celery.py", line 488, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/base.py", line 276, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/base.py", line 478, in setup_app_from_commandline
self.app = self.find_app(app)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/base.py", line 500, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/app/utils.py", line 345, in find_app
sym = symbol_by_name(app, imp=imp)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/bin/base.py", line 503, in symbol_by_name
return imports.symbol_by_name(name, imp=imp)
File "/home/analytics/ENV/lib/python3.5/site-packages/kombu/utils/imports.py", line 56, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/home/analytics/ENV/lib/python3.5/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "/home/analytics/ENV/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 665, in exec_module
File "", line 222, in _call_with_frames_removed
File "/home/analytics/messages/tasks.py", line 5, in 
@app.tasks
TypeError: 'TaskRegistry' object is not callable

Question: What am I doing wrong?

Answer:

Use @app.task instead of @app.tasks .

Scroll to Top
AllEscort