celery beat raised exception : error('cannot add item to database',)错误解决方法

在一次重启python中的celery-beat任务中,发现celery-beat启动不起来了。报错信息如下:

celery beat v4.1.0 (latentcall) is starting.
__    -    ... __   -        _
LocalTime -> 2018-04-11 15:04:12
Configuration ->
    . broker -> redis://127.0.0.1:9736/4
    . loader -> celery.loaders.app.AppLoader
    . scheduler -> celery.beat.PersistentScheduler
    . db -> celerybeat-schedule
    . logfile -> [stderr]@%WARNING
    . maxinterval -> 5.00 minutes (300s)
[2018-04-11 15:04:12,478: CRITICAL/MainProcess] beat raised exception : error('cannot add item to database',)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/kombu/utils/objects.py", line 42, in __get__
    return obj.__dict__[self.__name__]
KeyError: 'scheduler'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/shelve.py", line 111, in __getitem__
    value = self.cache[key]
KeyError: 'entries'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/celery/beat.py", line 485, in _create_schedule
    self._store[str('entries')]
  File "/usr/local/lib/python3.6/shelve.py", line 113, in __getitem__
    f = BytesIO(self.dict[key.encode(self.keyencoding)])
KeyError: b'entries'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/celery/apps/beat.py", line 107, in start_scheduler
    service.start()
  File "/usr/local/lib/python3.6/site-packages/celery/beat.py", line 549, in start
    humanize_seconds(self.scheduler.max_interval))
  File "/usr/local/lib/python3.6/site-packages/kombu/utils/objects.py", line 44, in __get__
    value = obj.__dict__[self.__name__] = self.__get(obj)
  File "/usr/local/lib/python3.6/site-packages/celery/beat.py", line 593, in scheduler
    return self.get_scheduler()
  File "/usr/local/lib/python3.6/site-packages/celery/beat.py", line 588, in get_scheduler
    lazy=lazy,
  File "/usr/local/lib/python3.6/site-packages/celery/beat.py", line 428, in __init__
    Scheduler.__init__(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/celery/beat.py", line 206, in __init__
    self.setup_schedule()
  File "/usr/local/lib/python3.6/site-packages/celery/beat.py", line 456, in setup_schedule
    self._create_schedule()
  File "/usr/local/lib/python3.6/site-packages/celery/beat.py", line 489, in _create_schedule
    self._store[str('entries')] = {}
  File "/usr/local/lib/python3.6/shelve.py", line 125, in __setitem__
    self.dict[key.encode(self.keyencoding)] = f.getvalue()
_dbm.error: cannot add item to database

解决办法:
1.删除启动目录中的celerybeat-schedule.db(我的项目地址为/data/www/master/project,在这目录下你发现有个 celerybeat-schedule.db文件,删除即可
2.再重新启动 ( celery beat -A project.celery_job )

原因:
当celerybeat启动的时候会带启动目录中生成 celerybeat-schedule.db作为数据存储的文件,当celerybeat异常关闭时,此文件没有被删除,在下一下启动的时候,被占用,导致_dbm.error: cannot add item to database错误。所以把文件删除就可以了


你可能感兴趣的:(Celery【python】)