Reputation: 98
I am trying to run a task in django view asynchronously. For that i am using celery and rabbitmq. By following the guide for small scale context i have defined task in my module(servicenow.py) as -
app = Celery('servicenow',broker='amqp://username:password@localhost:15672')
.
.
@app.task
def get_ITARAS_dump(self):
.
.
self.update_state(state='PROGRESS',meta={'current':i,'total':len(taskList)})
My rabbitmq server is running within brew services
After this i tried to start a worker instance with
celery -A servicenow worker -l info
then i the error message as -
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/bin/celery", line 11, in <module>
sys.exit(main())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/__main__.py", line 30, in main
main()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 793, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/base.py", line 311, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 785, in handle_argv
return self.execute(command, argv)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/celery.py", line 717, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/worker.py", line 179, in run_from_argv
return self(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/base.py", line 274, in __call__
ret = self.run(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/bin/worker.py", line 194, in run
pool_cls = (concurrency.get_implementation(pool_cls) or
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/concurrency/__init__.py", line 29, in get_implementation
return symbol_by_name(cls, ALIASES)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kombu/utils/__init__.py", line 96, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/concurrency/prefork.py", line 20, in <module>
from celery.concurrency.base import BasePool
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/concurrency/base.py", line 21, in <module>
from celery.utils import timer2
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/celery/utils/timer2.py", line 19
from kombu.async.timer import Entry, Timer as Schedule, to_timestamp, logger
^
SyntaxError: invalid syntax
I think this is a version issue but according to requirements i think i have it correct
django-celery==3.2.2
- celery [required: >=3.1.15,<4.0, installed: 3.1.26.post2]
- billiard [required: >=3.3.0.23,<3.4, installed: 3.3.0.23]
- kombu [required: >=3.0.37,<3.1, installed: 3.0.37]
- amqp [required: >=1.4.9,<2.0, installed: 1.4.9]
- anyjson [required: >=0.3.3, installed: 0.3.3]
- pytz [required: >dev, installed: 2018.7]
- django [required: >=1.8, installed: 2.1.3]
- pytz [required: Any, installed: 2018.7]
Please help, I cannot figure if i am missing a step in configuration or version issue. Also, if someone can verify these steps are correct in order to perform a async task on module level with celery. Thanks!
Upvotes: 0
Views: 4539
Reputation: 489
The issue is because you are using python 3.7. Downgrading it to python 3.6 will solve the error. For mac user to downgrade to python 3.6
$ brew unlink python
$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/e128fa1bce3377de32cbf11bd8e46f7334dfd7a6/Formula/python.rb
$ brew switch python 3.6.5
Upvotes: 0
Reputation: 8006
There's a conflict on the result backend code. Quick fix is to disable the result backed setting, e.g.
# CELERY_RESULT_BACKEND = 'redis://redis'
Upvotes: 1
Reputation: 51988
Well, its a known issue for Celery. Celery does not support python 3.7 yet. Same goes to Kombu. So downgrade python to 3.6 or former. You can check the status of that issue at https://github.com/celery/celery/issues/4500
Upvotes: 5