我创建了一个测试可执行文件,看看我是否可以捕获由 Supervisord 监控的程序的输出。
测试器.py:
#! /usr/bin/env python
import time, os
pid = os.getpid()
print "EXECUTING ON %s" % pid
while True:
time.sleep(5)
print "HOLLER %s" % pid
supervisord.conf:
[program:mytester]
command={path}/tester.py
但是当我尝试在 supervisorctl 中的进程上运行 tail
时,什么也没有。
最佳答案
自从您提问以来已经有一段时间了,但如果您仍然感兴趣,并且对于任何遇到同样问题的人:
在这种情况下,Python 正在缓冲输出,在刷新到标准输出之前您不会看到它。您可以在您的程序中使用 sys.stdout.flush()
强制刷新,但最干净的修复方法可能是在无缓冲模式中运行您的脚本并使用 -u
Python 解释器的标志:
supervisord.conf
[program:mytester]
command=python -u {path}/tester.py
(有同样的问题,在supervisord的mailing list中找到了解决方案)
关于python - 无法获得 supervisord 监控进程的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11968687/