2012-02-12 62 views
0

工作,我有它運行只是位於的runserver罰款Django項目:無法獲取的Django celeryd在Windows

D:\EverTabs\work\evertabs-website\src\evertabs\ 

我的settings.py和manage.py居住在上面的路徑。

我打開CMD可信賴的外殼,CD到該目錄,並運行manage.py celeryd,我出現以下錯誤的異常:

ImportError: Could not import settings 'evertabs.settings' (Is it on sys.path?): No module named evertabs.settings 

公平,足夠了。谷歌和StackOverflow救援,我找到了答案。我需要爲命令提供--settings=settings。奇怪的是,runserver並不需要--settings=settings,但這就是生活。我願意妥協。我不斷地得到一個錯誤:

Traceback (most recent call last): 
    File "C:\Progra~1\Python26\lib\multiprocessing\process.py", line 231, in _bootstrap 
    self.run() 
    File "C:\Progra~1\Python26\lib\multiprocessing\process.py", line 88, in run 
    self._target(*self._args, **self._kwargs) 
    File "c:\program files\python26\lib\site-packages\celery-2.4.6-py2.6.egg\celery\concurrency\processes\pool.py", line 173, in worker 
    initializer(*initargs) 
    File "c:\program files\python26\lib\site-packages\celery-2.4.6-py2.6.egg\celery\worker\__init__.py", line 64, in process_initializer 
    app.loader.init_worker() 
    File "c:\program files\python26\lib\site-packages\celery-2.4.6-py2.6.egg\celery\loaders\base.py", line 100, in init_worker 
    self.on_worker_init() 
    File "c:\program files\python26\lib\site-packages\django_celery-2.4.2-py2.6.egg\djcelery\loaders.py", line 92, in on_worker_init 
    autodiscover() 
    File "c:\program files\python26\lib\site-packages\django_celery-2.4.2-py2.6.egg\djcelery\loaders.py", line 114, in autodiscover 
    for app in settings.INSTALLED_APPS]) 
    File "c:\program files\python26\lib\site-packages\django_celery-2.4.2-py2.6.egg\djcelery\loaders.py", line 124, in find_related_module 
    app_path = importlib.import_module(app).__path__ 
    File "build\bdist.win32\egg\importlib\__init__.py", line 37, in import_module 
ImportError: No module named evertabs 

所以我抓我的頭大力和決定,也許如果我喂這傢伙不同的PYTHONPATH,他將很好地放置。我的下一個嘗試是:

manage.py celeryd --pythonpath=D:\EverTabs\work\evertabs-website\src\ 

現在我們正在某個地方!沒有錯誤。但是,我的celeryconfig.py與settings.py位於同一目錄中,沒有得到處理。我的任務都沒有加載。我儘可能把一個語法錯誤放入celeryconfg.py來證明自己沒有被加載。

我做的下一步是從django 1.4中使用manage.py。這個manage.py被放置在D:\EverTabs\work\evertabs-website\src\而不是D:\EverTabs\work\evertabs-website\src\evertabs\。在這一點上,我可以用簡單的語法執行芹菜,而不必添加到pythonpath中。儘管如此,我celeryconfig.py是保持不變:

D:\EverTabs\work\evertabs-website\src>manage.py celeryd 

進一步的研究表明,如果我添加一個tasks.py到我的頂級目錄9where setting.py所在地)。芹菜將自動發現它們。這工作。然而,celeryconfig.py仍然沒有被處理,所以我不能在那裏做更復雜的配置。現在,這不是一個問題,因爲我的任務終於找到了。但是,它大大困擾我celeryconfig.py沒有被處理。

現在,我認爲現代芹菜可能並不尋找celeryconfig.py。我可以簡單地將這些設置放在我的settings.py中,芹菜就可以把它們提取出來。事情開始看起來不錯。

回答

1

django-celery使用settings.py作爲芹菜配置文件。

The other main difference is that configuration values are stored in your Django projects’ settings.py module rather than in celeryconfig.py.

http://ask.github.com/django-celery/introduction.html

+0

呀,這將是有幫助的配置之前閱讀整個文檔。然而,本教程的開始部分提到,將django-celery設置起來比聽起來容易得多,所以我隨着營銷信息一起去了。 – 2012-02-13 10:24:08

0

的事情我沒有得到簡短的摘要芹菜工作:

  1. 二者必選其一--pythonpath指向上述項目目錄的目錄,這樣芹菜能導入project.settings或移動manage.py了一個級別並使用django 1.4生成的manage.py。

  2. 在您的項目頂層(settings.py所在位置)創建一個tasks.py,然後芹菜會自動發現它們。如果您想使用其他模塊,請將CELERY_IMPORTS = ("yourproject.anothermodule",)添加到您的settings.py中,以便芹菜可以查看anothermodule的任務內容。

  3. 忘記celeryconfig.py這是在某些文檔中提到的。只需將所有設置放在您的地址settings.py