2017-05-31 2 views
0

Ich habe ein einfaches Sellerie-Projekt erstellt. Die Struktur ist wie folgt:Sellerie Projekt hat keine Eigenschaft 'app'

+--parent 
| +--sm 
| | +--__init__.py 
| | +--celery.py 
| | +--celeryconfig.py 
| | +--tasks.py 
| +--__init__.py 
| +--runner.py 
| +--numlist.csv 

celery.py:

from future import absolute_import 
from celery import Celery 
app = Celery("sm") 
app.config_from_object('sm.celeryconfig') 
app.conf.update(CELERY_TASK_RESULT_EXPIRES=3600,) 
if __name__ == '__main__': 
    app.start() 

celeryconfig.py:

from __future__ import absolute_import 
CELERY_IMPORTS=("sm.tasks") 
BROKER_URL = "amqp://guest:[email protected]:5672//" 
CELERY_RESULT_BACKEND = "localhost:5672//" 
CELERY_ROUTES = {'sm.tasks.add_sub': {'queue': 'add_sub'}, 
     'sm.tasks.multiply':{'queue':'multiply'} 
     } 
CELERY_CREATE_MISSING_QUEUES = True 
CELERY_MESSAGE_COMPRESSION = 'bzip2' 
CELERYD_PREFETCH_MULTIPLIER = 1 
CELERY_DEFAULT_QUEUE = 'sm_celery' 

tasks.py:

from sm.celery import app 
import logging 
logger = logging.getLogger(__name__) 
logger.setLevel(logging.INFO) 

@app.task(queue='add_sub') 
def add_sub(line): 
    try: 
     a = int(line.split(",")[0]) 
     b = int(line.split(",")[1]) 
     sums = a+b 
     subs = a-b 
     return (sums, subs) 
    except Exception as e: 
     logger.error("Something wrong in add_sub. Inputs are line= 
     {0}".format(line)) 

@app.task(queue='multiply') 
def multiply(nos): 
    try: 
     a = nos[0] 
     b = nos[1] 
     return a*b 
    except Exception as e: 
     logger.error("Something wring in multiply. Inputs are nos= 
    {0}".format(nos)) 

ich den Fehler wenn ich versuche, einen Arbeiter zu starten oder wenn ich den Status von celer überprüfe y:

celery -A sm status 

Unten ist der Fehler:

Traceback (most recent call last): 
    File "c:\anaconda3\lib\site-packages\celery\app\utils.py", line 361, in 
find_app 
    found = sym.app 
AttributeError: module 'sm' has no attribute 'app' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "c:\anaconda3\lib\runpy.py", line 184, in _run_module_as_main 
    "__main__", mod_spec) 
    File "c:\anaconda3\lib\runpy.py", line 85, in _run_code 
    exec(code, run_globals) 
    File "C:\Anaconda3\Scripts\celery.exe\__main__.py", line 9, in <module> 
    File "c:\anaconda3\lib\site-packages\celery\__main__.py", line 14, in main 
    _main() 
    File "c:\anaconda3\lib\site-packages\celery\bin\celery.py", line 326, in 
main 
    cmd.execute_from_commandline(argv) 
    File "c:\anaconda3\lib\site-packages\celery\bin\celery.py", line 488, in 
execute_from_commandline 
    super(CeleryCommand, self).execute_from_commandline(argv))) 
    File "c:\anaconda3\lib\site-packages\celery\bin\base.py", line 279, in 
execute_from_commandline 
    argv = self.setup_app_from_commandline(argv) 
    File "c:\anaconda3\lib\site-packages\celery\bin\base.py", line 481, in 
setup_app_from_commandline 
    self.app = self.find_app(app) 
    File "c:\anaconda3\lib\site-packages\celery\bin\base.py", line 503, in 
find_app 
    return find_app(app, symbol_by_name=self.symbol_by_name) 
    File "c:\anaconda3\lib\site-packages\celery\app\utils.py", line 366, in 
find_app 
    found = sym.celery 
AttributeError: module 'sm' has no attribute 'celery' 

Laufen auf einem Windows-Rechner. Python-Version: Python 3.5.2 :: Anaconda 4.1.1 (64-Bit)

Antwort

1

Haben Sie in Ihrer celery.py Datei versucht, dem future Import Unterstriche hinzuzufügen? zB:

from __future__ import absolute_import 
from celery import Celery 
app = Celery("sm") 
... 

Sie haben Zugriff auf Windows jetzt nicht, aber ich versuchte, Ihre App auf einem Ubuntu-Rechner ausgeführt wird. Bin in einen ImportError gelaufen, bis ich den future Import in celery.py repariert habe. Habe keine AttributeErrors gefunden.

Verwandte Themen