3
我有一個芹菜燒瓶應用程序。
當我運行工人如下:芹菜 - 工人退出exitcode1的燒瓶
celery -A app.celery worker
我得到以下輸出
-------------- [email protected] v3.1.22 (Cipater)
---- **** -----
--- * *** * -- Windows-7-6.1.7601-SP1
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: app:0x483e668
- ** ---------- .> transport: mongodb://localhost:27017/app
- ** ---------- .> results: mongodb://localhost:27017/app
- *** --- * --- .> concurrency: 8 (prefork)
-- ******* ----
--- ***** ----- [queues]
-------------- .> celery exchange=celery(direct) key=celery
[2016-03-08 15:52:05,587: WARNING/MainProcess] [email protected] ready.
[2016-03-08 15:52:08,855: ERROR/MainProcess] Process 'Worker-8' pid:9720 exited with 'exitcode 1'
[2016-03-08 15:52:08,855: ERROR/MainProcess] Process 'Worker-7' pid:11940 exited with 'exitcode 1'
[2016-03-08 15:52:08,856: ERROR/MainProcess] Process 'Worker-6' pid:13120 exited with 'exitcode 1'
...
它去無休止地和CPU提高到100%。
相關的配置是:
CELERY_BROKER_URL = 'mongodb://localhost:27017/app'
CELERY_RESULT_BACKEND = 'mongodb://localhost:27017/'
CELERY_MONGODB_BACKEND_SETTINGS = {
'database': 'app',
'taskmeta_collection': 'my_taskmeta_collection',
}
CELERY_IMPORTS = ('app.tasks',)
CELERYD_FORCE_EXEC = True
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
我的項目結構是:
proj/
config.py
app/
__init__.py
tasks.py
views.py
這是我如何配置我的___init___.py芹菜「:
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
def make_celery(app):
celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
celery = make_celery(app)
這是我在tasks.py
from app import celery
@celery.task()
def add_together(a, b):
return a + b
更新
當我刪除從配置以下行文件的工人不退出
CELERY_IMPORTS = ('app.tasks',)
,但我得到以下錯誤
Traceback (most recent call last):
File "d:\python34\lib\site-packages\celery\worker\consumer.py", line 456, in on_task_received
strategies[name](message, body,
KeyError: 'app.tasks.add_together'
您的任務在哪裏定義?即'app.celery.py'中的內容? – scytale
在tasks.py中我有通用的add_numbers示例 –
我沒有app.celery.py我在app.__init__.py中創建了一個芹菜對象,正如我在問題 –