背景:项目在公司的一台虚拟机上运行(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的仇的更多相关文章

  1. celery 异步任务小记

    这里有一篇写的不错的:http://www.jianshu.com/p/1840035cb510 自己的"格式化"后的内容备忘下: 我们总在说c10k的问题, 也做了不少优化, 然 ...

  2. celery 入门

    认识 这里有几个概念,task.worker.broker.顾名思义,task 就是老板交给你的各种任务,worker 就是你手下干活的人员. 那什么是 Broker 呢? 老板给你下发任务时,你需要 ...

  3. celery入门

    认识 这里有几个概念,task.worker.broker.顾名思义,task 就是老板交给你的各种任务,worker 就是你手下干活的人员. 那什么是 Broker 呢? 老板给你下发任务时,你需要 ...

  4. 异步任务--celery发送邮件

    安装两个python包: pip install celery==3.1.25 pip install django-celery==3.1.17 在配置文件settings.py中做如下配置: a) ...

  5. celery 原理理解

    这里有一篇写的不错的:http://www.jianshu.com/p/1840035cb510 自己的“格式化”后的内容备忘下: 我们总在说c10k的问题, 也做了不少优化, 然后优化总是不够的. ...

  6. celery 实例进阶

    认识 这里有几个概念,task.worker.broker.顾名思义,task 就是老板交给你的各种任务,worker 就是你手下干活的人员. 那什么是 Broker 呢? 老板给你下发任务时,你需要 ...

  7. celery异步任务 定时任务

    以前项目中用到过 celery ,但是没怎么记笔记,现在在记一下,方便以后用.   Celery.png 问:Celery 是什么? 答:Celery 是一个由 Python 编写的简单.灵活.可靠的 ...

  8. [源码解析] 并行分布式框架 Celery 之 Lamport 逻辑时钟 & Mingle

    [源码解析] 并行分布式框架 Celery 之 Lamport 逻辑时钟 & Mingle 目录 [源码解析] 并行分布式框架 Celery 之 Lamport 逻辑时钟 & Ming ...

  9. 异步任务队列Celery在Django中的使用

    前段时间在Django Web平台开发中,碰到一些请求执行的任务时间较长(几分钟),为了加快用户的响应时间,因此决定采用异步任务的方式在后台执行这些任务.在同事的指引下接触了Celery这个异步任务队 ...

随机推荐

  1. Ubuntu 链接ln的使用:创建和删除符号链接

    一 . 使用方式 ln [option] source_file dist_file (source_file是待建立链接文件的文件,dist_file是新创建的链接文件) -f 建立时,将同档案名删 ...

  2. [Array]167. Two Sum II - Input array is sorted

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  3. warning: deprecated conversion from string constant to 'char*

    warning: deprecated conversion from string constant to 'char* #include<iostream> using namespa ...

  4. nginx链接末尾自动补全斜杠

    放在locaation里边就行 if (-d $request_filename){ rewrite ^(.*[^/])$ $/ permanent;#加斜杠 } 这样,nginx就会进行判断了,如果 ...

  5. proteus 8.8 直装版提示Symbol $MKRORIGIN used but not found in libraries 安装后没有库

    用管理员运行程序,然后再通过菜单打开仿真文件是没问题. 解决方法:通常的安装目录是C:\Program Files (x86)\Labcenter Electronics\Proteus 8 Prof ...

  6. Django高级实战 开发企业级问答网站

    Django高级实战 开发企业级问答网站 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身没问题,大家看的 ...

  7. matplotlib无法显示中文

    import matplotlib as mpl mpl.rcParams['font.sans-serif'] = ['KaiTi']mpl.rcParams['font.serif'] = ['K ...

  8. 工作记录--使用FFmpeg将一个视频文件中音频合成到另一个视频中

    由于工作需要,临时被老大吩咐去研究一个FFmpeg工具,通过linux命令行去将一个视频中的音频提取出来并合成到另一个视频中,最终的效果是要保证2个视频中的音频都在一个视频中播放. 但是本人对FFmp ...

  9. PYTHON网络爬虫与信息提取[网络爬虫协议](单元二)

    robots.txt在网站的根目录下 遵守 自动或人工识别robots.txt再进行内容爬取 约束性:建议性,不遵守协议,存在法律风险. 基本语法: User-agent: * Disallow: / ...

  10. Zookeeper 扫盲

    Zookeeper 扫盲 :disappointed_relieved: 配置文件详解: tickTime:基本事件单元,以毫秒为单位,这个时间作为 Zookeeper 服务器之间或客户端之间维持心跳 ...