记一次Celery的仇
背景:项目在公司的一台虚拟机上运行(32核+32G)。其他人的项目也在这台物理机上运行。。我的训练代码是单进程的,跑完一次需要大约10h(数据量大逮着一个核使劲跑。。);训练是一个Celery定时任务;我开始训练时就有人提出他们的项目慢的卡着了。。
改进:用多进程改进了训练过程中阻塞的地方。这时就出问题了,在Celery进程中运行创建子进程时报错:AssertionError: daemonic processes are not allowed to have children(“不允许在守护进程中创建子进程”)
解决办法:
1,在终端设置环境变量启用优化模式,export PYTHONOPTIMIZE=1,再执行celery -A app.celery.base worker -l info -n socwebai就行了
2,如果用的multiprocessing,重写一个Mypool:https://stackoverflow.com/questions/6974695/python-process-pool-non-daemonic(没试)
用方法1可以在本地测试运行了。
修改服务器上supervisor
command = export PYTHONOPTIMIZE=1 && /home/ldy/workspace/socwebai/venv_socwebai/bin/celery -A app.celery.base worker -l info -n socwebai
supervisor报错找不到export
查资料发现可以指定Celery 的 -O参数:
there are two method to solve this problem ,disable assert:
1.where celery starts set export PYTHONOPTIMIZE=1 OR start celery with this parameter -O OPTIMIZATION
2.disable python packet multiprocessing process.py line 102:
assert not _current_process._config.get(‘daemon’), \ ‘daemonic processes are not allowed to have children’
试了下面几条命令,还是提示不能创建子进程
celery -A app.celery.base -Q worker -l info -n socwebai
celery -A app.celery.base worker -l info -n socwebai -Q
celery -A app.celery.base worker -l info -n socwebai -Q 1
不熟悉-O参数鸭!
今天,问题解决了。
放弃supervisor改用systemd开机自启celery,ubuntu18.04 systemd开机自启教程。
将文中rc.local文件替换如下:
#!/bin/bash echo "PowerBoot strating..." > /var/www/socwebai/PowerBoot.log cd /var/www/socwebai/
source venv_socwebai/bin/activate export PYTHONOPTIMIZE=1
echo "ok" >> /var/www/socwebai/PowerBoot.log
celery -A app.celery.base worker -l info -n socwebai >> /var/www/socwebai/PowerBoot.log 2>&1 & echo "okk" >> /var/www/socwebai/PowerBoot.log
celery beat -A app.celery.tasks.train_model >> /var/www/socwebai/PowerBoot.log 2>&1 & echo "finished!" >> /var/www/socwebai/PowerBoot.log
sudo reboot 重启后,任务就启动了。一个celery worker,一个celery beat.

重点提一下rc.local部分:“ >> /var/www/socwebai/PowerBoot.log 2>&1 &”
在没加该部分开机自启时,执行完celery -A app.celery.base worker -l info -n socwebai终端被占用,无法继续向下执行,该部分的作用是:把当前终端放到后台,继续向下执行。
记一次Celery的仇的更多相关文章
- celery 异步任务小记
这里有一篇写的不错的:http://www.jianshu.com/p/1840035cb510 自己的"格式化"后的内容备忘下: 我们总在说c10k的问题, 也做了不少优化, 然 ...
- celery 入门
认识 这里有几个概念,task.worker.broker.顾名思义,task 就是老板交给你的各种任务,worker 就是你手下干活的人员. 那什么是 Broker 呢? 老板给你下发任务时,你需要 ...
- celery入门
认识 这里有几个概念,task.worker.broker.顾名思义,task 就是老板交给你的各种任务,worker 就是你手下干活的人员. 那什么是 Broker 呢? 老板给你下发任务时,你需要 ...
- 异步任务--celery发送邮件
安装两个python包: pip install celery==3.1.25 pip install django-celery==3.1.17 在配置文件settings.py中做如下配置: a) ...
- celery 原理理解
这里有一篇写的不错的:http://www.jianshu.com/p/1840035cb510 自己的“格式化”后的内容备忘下: 我们总在说c10k的问题, 也做了不少优化, 然后优化总是不够的. ...
- celery 实例进阶
认识 这里有几个概念,task.worker.broker.顾名思义,task 就是老板交给你的各种任务,worker 就是你手下干活的人员. 那什么是 Broker 呢? 老板给你下发任务时,你需要 ...
- celery异步任务 定时任务
以前项目中用到过 celery ,但是没怎么记笔记,现在在记一下,方便以后用. Celery.png 问:Celery 是什么? 答:Celery 是一个由 Python 编写的简单.灵活.可靠的 ...
- [源码解析] 并行分布式框架 Celery 之 Lamport 逻辑时钟 & Mingle
[源码解析] 并行分布式框架 Celery 之 Lamport 逻辑时钟 & Mingle 目录 [源码解析] 并行分布式框架 Celery 之 Lamport 逻辑时钟 & Ming ...
- 异步任务队列Celery在Django中的使用
前段时间在Django Web平台开发中,碰到一些请求执行的任务时间较长(几分钟),为了加快用户的响应时间,因此决定采用异步任务的方式在后台执行这些任务.在同事的指引下接触了Celery这个异步任务队 ...
随机推荐
- python中常见的错误
python中常见的错误 1.IndentationError: unindent does not match any outer indentation leve 众所周知,Python语法要 ...
- svn: E170013: Unable to connect to a repository at URL svn: E230001: Server SSL certificate verification
idea更新项目报E230001: Server SSL certificate verification failed: certificate issued for a different hos ...
- [Array]122. Best Time to Buy and Sell Stock II(obscure)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- SSM-5zookeeper在LINUX上自启
把zookeeper做成服务 1.进入到/etc/rc.d/init.d目录下,新建一个zookeeper脚本 [root@zookeeper ~]# cd /etc/rc.d/init.d/ [ro ...
- 主流浏览器HTML5视频格式差异
因最近在研究video.js,现在遇到的问题是在js中设置了swf,但是在ie8下只是显示黑屏并没有播放视频,在网上进行搜索时查到了有关各个浏览器支持哪些视频格式的文章,现在此记录下,方便以后查阅. ...
- 搭建单向HTTPS
//参考网址:https://blog.csdn.net/haolipengzhanshen/article/details/51278262 //打开CMD窗口 cd C:\wamp\bin\apa ...
- grpc安装
整个过程就是: 1.客户端 发送 数据(以字节流的方式) 2.服务端接收,并解析. 根据 约定 知道要知道执行什么.然后把结果返回客户端 RPC就是 把 1.上述过程封装下,使其操作更加优化 2.使用 ...
- [jnhs]hibernate只能创建一张/表不创建表com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'kaihu.t_client_info' doesn't exist和org.hibernate.exception.SQLGrammarException: could not execute statement
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'kaihu.t_client_info' doesn't exist ...
- Linux 基础命令4进程
ID和PID的产生 ps( process status) 查看现在的进程 上例中,列出了两个进程,进程 5198 和进程 10129,各自代表命令 bash 和 ps.正如我们所看到的, 默认情况下 ...
- java 5 绘图GUI
---恢复内容开始--- 绘图的基本原理 color 在awt包里面 字体的相关类 Graphics类常用方法 JFrame 继承JFrame就有主窗口了 Java2D API 绘图的例子 了解Swi ...