背景:项目在公司的一台虚拟机上运行,配置: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 (没试)
用方法一可以在本地测试运行了。
修改服务器上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参数没用对吗?怎么才能运行起来???