背景

在进行celery定时任务测试时,发现到点任务并未执行,检查了log发现在启动celery beat的时候有这样一个报错,所以celery beat并未启动成功。

1
2
3
4
(hzinfo) E:PythonWorkSpacehzinfo>celery beat v3.1.0 (Cipater) is starting.
ERROR: Pidfile (celerybeat.pid) already exists.
Seems we're already running? (pid: 22220)
* Restarting with stat

排查

celery beat在运行时,会自动创建两个文件:

  • pidfile:默认为celerybeat.pid,保存在项目根目录。
  • scheduler:默认为celerybeat-schedule,保存在项目根目录。

这里的报错说明pidfile已存在。

看下官网的说明

–pidfile

File used to store the process pid. Defaults to celerybeat.pid.

The program won’t start if this file already exists and the pid is still alive.

上次运行的时候,已经自动创建了,进程结束的时候并未自动删除,从而导致再次运行的时候报错了。

直接删除这个pidfile文件,再次启动celery beat

大专栏  celery beat之pidfile already exists问题e class="highlight shell">

1
celery -A manage.celery beat -s "celery_app/celerybeat-schedule"

运行成功了。

那么难道每次重启都得先删除么?

虽然官网上没提,但是参考网上说法,如果在启动celery beat的时候配置pidfile参数,并将该参数设置为空,可以规避这个问题。

1
start /b celery -A manage.celery beat -s "celery_app/celerybeat-schedule" --pidfile=

测试了下,果然并没有生成pidfile,且程序也运行成功了。

总结

celery beat在运行时会生成一个pidfile文件用于记录当前的pid。且该文件不会因进程的结束而自动删除。当再次创建celery beat进程的时候,会因为已存在这个文件而启动失败。

解决方式有两种:

  • 在启动前检测是否存在改文件并删除后再启动

  • 通过启动时指定空参数的方式规避:

    1
    celery -A manage.celery beat -s "celery_app/celerybeat-schedule" --pidfile=

celery beat之pidfile already exists问题的更多相关文章

  1. Celery beat实现定时/轮询任务

    Celery定时任务 配置 启用Celery的定时任务需要设置CELERYBEAT_SCHEDULE .  Celery的定时任务都由celery beat来进行调度.celery beat默认按照s ...

  2. django 异步任务实现及Celery beat实现定时/轮询任务

    Celery定时任务 requirements celery==3.1.25 异步任务 django-celery==3.2.2 定时任务管理包 redis==2.10.6 django-redis- ...

  3. [python基础] celery beat/task/flower解析

    一.Celery 介绍 Celery 是一个强大的分布式任务队列,它可以让任务的执行完全脱离主程序,甚至可以被分配到其他主机上运行.我们通常使用它来实现异步任务( async task )和定时任务( ...

  4. celery beat - 心跳包

    celery -A 项目名 beat -l info -S django# 启动心跳任务 celery -A 项目名  worker -l info # 启动1个worker去执行

  5. windows中执行celery beat任务

    由于最新的celery4.2不支持windows系统,因此按照网上的建议安装了3.1.25版.按照官网的说明使用 app.conf.beat_schedule = { 'add-every-30-se ...

  6. django+celery 实现定时任务

    利用 celery 实现定时任务 celery支持定时任务,设定好任务的执行时间,celery就会定时自动帮你执行, 这个定时任务模块叫celery beat Celery安装 由于celery 4. ...

  7. Celery的实践指南

    http://www.cnblogs.com/ToDoToTry/p/5453149.html Celery的实践指南   Celery的实践指南 celery原理: celery实际上是实现了一个典 ...

  8. Python 任务队列 Celery

    一. celery 简介 Celery 是一个专注于实时处理和任务调度的分布式任务队列, 同时提供操作和维护分布式系统所需的工具.. 所谓任务就是消息, 消息中的有效载荷中包含要执行任务需要的全部数据 ...

  9. 定时任务调度-Celery

    确保任务不重叠解决方法: from celery import task from celery.five import monotonic from celery.utils.log import ...

随机推荐

  1. 吴裕雄--天生自然TensorFlow高层封装:解决ValueError: Invalid backend. Missing required entry : placeholder

    找到对应的keras配置文件keras.json 将里面的内容修改为以下就可以了

  2. 吴裕雄--天生自然 pythonTensorFlow图形数据处理:解决module 'tensorflow' has no attribute 'Session'

    原因:因为是tensorflow 2.0版本

  3. 一、linux-mysql 运维DBA介绍

    一.DBA数据库管理人员需要在整个架构中解决数据库的压力,前端业务通过扩展,加机器就可以很好的解决,但是存储.数据库就不是很好的可以进行扩展,数据也是分配不均的,所以,1)通过在数据库前面添加Memc ...

  4. sql 新增随机数

    update RemoteDetection set humidity=round((rand()*3+29),0),TEMPERATURE=round((rand()*3+16),0),atmosp ...

  5. 关于vyos 防火墙配置

    VyOS是一个基于Debian的网络操作系统,是Vyatta的社区fork.Vyatta是博通的企业级的产品,通过这套系统,能在x86平台提供路由,防火墙和×××的功能. 这个系统提供了和其他诸如Ci ...

  6. aclocal-1.13: command not found

    原因: 将编译好的工程拷贝到系统版本不一样的系统中,再进行编译会出现此类问题. 解决方法: yum install automake autoconf yum install libtool auto ...

  7. 3.redis kyes命令

    Keys命令 1.1设置key的生存时间 Redis在实际使用过程中更多的用作缓存,然而缓存的数据一般都是需要设置生存时间的,即:到期后数据销毁. EXPIRE key seconds         ...

  8. peewee 对 mysql 类型支持问题,并不支持bit

    这个问题是当时想当然了 看到python BooleanField(default=False) 便认为 对应 mysql的bit 出现问题 mysql实际字段存储值为0,但 peewee orm 后 ...

  9. Array.prototype.slice.call()方法的理解

    1.基础1)slice() 方法可从已有的数组中返回选定的元素. start:必需.规定从何处开始选取.如果是负数,那么它规定从数组尾部开始算起的位置.也就是说,-1 指最后一个元素,-2 指倒数第二 ...

  10. 用户增删改查 django生命周期 数据库操作

    一 django生命周期 1 浏览器输入一个请求(get/post)2 响应到django程序中3 执行到url,url通过请求的地址匹配到不同的视图函数4 执行对应的视图函数,此过程可以查询数据库, ...