2

My first Celery program looks like this - I am pretty much following the getting started instructions:

from celery import Celery

import time

app = Celery(
    "celery_test",
    broker="redis://",
    backend="redis://"
)

@app.task
def greet(who):
    print(f"Hello {who}")

@app.task
def add(x, y):
    return x + y

@app.task
def long(sleep_time):
    time.sleep(sleep_time)

Trying to set the result backend via backend='redis://' results in the following syntax error when calling celery -A celery_test worker --loglevel=info, which looks like a bug in Celery:

[2019-01-21 12:58:59,457: CRITICAL/MainProcess] Unrecoverable error: SyntaxError('invalid syntax', ('/Users/cls/anaconda3/lib/python3.7/site-packages/celery/backends/redis.py', 22, 19, 'from . import async, base\n'))
Traceback (most recent call last):
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/kombu/utils/objects.py", line 42, in __get__
    return obj.__dict__[self.__name__]
KeyError: 'backend'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/worker/worker.py", line 205, in start
    self.blueprint.start(self)
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/bootsteps.py", line 115, in start
    self.on_start()
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/apps/worker.py", line 139, in on_start
    self.emit_banner()
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/apps/worker.py", line 154, in emit_banner
    ' \n', self.startup_info(artlines=not use_image))),
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/apps/worker.py", line 217, in startup_info
    results=self.app.backend.as_uri(),
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/kombu/utils/objects.py", line 44, in __get__
    value = obj.__dict__[self.__name__] = self.__get(obj)
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/app/base.py", line 1196, in backend
    return self._get_backend()
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/app/base.py", line 914, in _get_backend
    self.loader)
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/app/backends.py", line 70, in by_url
    return by_name(backend, loader), url
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/app/backends.py", line 50, in by_name
    cls = symbol_by_name(backend, aliases)
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/kombu/utils/imports.py", line 56, in symbol_by_name
    module = imp(module_name, package=package, **kwargs)
  File "/Users/cls/anaconda3/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 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 860, in get_code
  File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/cls/anaconda3/lib/python3.7/site-packages/celery/backends/redis.py", line 22
    from . import async, base
                      ^
SyntaxError: invalid syntax

I would like to verify that this is indeed a bug and not an issue with my configuration. Also I'd rather get started with asynchronous programming than with writing bug reports, so a workaround would be appreciated.

clstaudt
  • 21,436
  • 45
  • 156
  • 239

1 Answers1

2

It seems that celery doesn't work in python 3.7 yet, only python 3.6 or lower. You can find a workaround in trouble in setting celery tasks backend in Python

Anna Krogager
  • 3,528
  • 16
  • 23
  • async is a keyword and the PEP is from 2015 and for 3.5. Is the celery project abandoned or something? https://www.python.org/dev/peps/pep-0492/ – clstaudt Jan 21 '19 at 16:13
  • For a year now - clearly I must be underestimating the complexity of this refactoring step. ;) Anyway, thanks for the clarification. – clstaudt Jan 21 '19 at 16:28