我刚开始使用 Django 芹菜并包含在我的项目中
但我在控制台中看不到打印语句或返回语句
我看了看这里:
Celery 计划任务中的打印语句未显示在终端中
简单的芹菜测试与打印不转到终端
系统: Windows, Pycharm , Python3, django 1.9, Celery 4.02, django-celery-beat 1.01
驱动器/芹菜.py
from __future__ import absolute_import, unicode_literals
from celery import Celery
from celery.schedules import crontab
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'advocate.local_settings')
app = Celery(
'drive',
broker='redis://localhost:6379/0',
include=['drive.celery_tasks']
)
app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.beat_schedule = {
'add-every-minute': {
'task': 'drive.celery_tasks.add',
'schedule': crontab(),
},
}
app.conf.timezone = 'UTC'
# Optional configuration, see the application user guide.
app.conf.update(
result_expires=3600,
)
if __name__ == '__main__':
app.start()
驱动器/celery_tasks.py
from __future__ import absolute_import, unicode_literals
from drive.celery import app
from datetime import datetime
@app.task
def add():
temp = str(datetime.now())
print(temp)
return 2 + 3
芹菜运行命令
celery -A drive beat -l info
在控制台中显示
LocalTime -> 2017-07-12 14:07:58
Configuration ->
. broker -> redis://localhost:6379/0
. loader -> celery.loaders.app.AppLoader
. scheduler -> celery.beat.PersistentScheduler
. db -> celerybeat-schedule
. logfile -> [stderr]@%INFO
. maxinterval -> 5.00 minutes (300s)
[2017-07-12 14:07:58,548: INFO/MainProcess] beat: Starting...
[2017-07-12 14:07:59,688: INFO/MainProcess] Scheduler: Sending due task add-every-minute (drive.celery_tasks.add)
[2017-07-12 14:08:00,779: INFO/MainProcess] Scheduler: Sending due task add-every-minute (drive.celery_tasks.add)
[2017-07-12 14:09:00,000: INFO/MainProcess] Scheduler: Sending due task add-every-minute (drive.celery_tasks.add)
当我开始工作芹菜 -A 驱动器工人 -1 信息
-------------- celery@Mathur v4.0.2 (latentcall)
---- **** -----
--- * *** * -- Windows-10-10.0.15063-SP0 2017-07-12 14:51:00
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: drive:0x351b290
- ** ---------- .> transport: redis://localhost:6379/0
- ** ---------- .> results: disabled://
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. drive.celery_tasks.add
. drive.celery_tasks.weekly_digest_mails
[2017-07-12 14:51:00,403: CRITICAL/MainProcess] Unrecoverable error: AttributeError("Can't pickle local object 'Pool.__init__.
<locals>.Process'",)
Traceback (most recent call last):
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesceleryworkerworker.py", line 203, in start
self.blueprint.start(self)
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagescelerybootsteps.py", line 119, in start
step.start(parent)
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagescelerybootsteps.py", line 370, in start
return self.obj.start()
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesceleryconcurrencybase.py", line 131, in start
self.on_start()
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesceleryconcurrencyprefork.py", line 112, in on_st
art
**self.options)
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesbilliardpool.py", line 1008, in __init__
self._create_worker_process(i)
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesbilliardpool.py", line 1117, in _create_worker_pr
ocess
w.start()
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesbilliardprocess.py", line 122, in start
self._popen = self._Popen(self)
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesbilliardcontext.py", line 383, in _Popen
return Popen(process_obj)
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesbilliardpopen_spawn_win32.py", line 79, in __init
__
reduction.dump(process_obj, to_child)
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesbilliardreduction.py", line 99, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'Pool.__init__.<locals>.Process'
(share) C:UsersVaibhavDesktopDoSelecttrueshareadvocate>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesbilliardspawn.py", line 165, in spawn_main
exitcode = _main(fd)
File "c:usersvaibhavdesktopdoselecttruesharesharelibsite-packagesbilliardspawn.py", line 207, in _main
self = pickle.load(from_parent)
EOFError: Ran out of input
您还需要启动一个工作线程。
celery -A drive worker -l info
如果您使用的是窗口,请检查此