gpt4 book ai didi

python - supervisord 日志不显示我的输出

转载 作者:IT老高 更新时间:2023-10-28 20:35:41 25 4
gpt4 key购买 nike

我有一个 [program:x] 正在运行,它会打印/sys.stdout.writes 很多东西。在 [supervisord] 的 AUTO childlogdir 或 [program:x] 的 stdout_logfile 中都没有出现我错过了什么吗?

如何捕获从 [program:x] 打印或标准输出的所有内容?

在我的程序中,我明确地同时做这两件事,

print "something"
sys.stdout.write("something")

相关的supervisord.conf文件

[supervisord]
childlogdir = %(here)s/../logs/supervisord/
logfile = %(here)s/../logs/supervisord/supervisord.log
logfile_maxbytes = 100MB
logfile_backups = 10
loglevel = info
pidfile = %(here)s/../logs/supervisord/supervisord.pid
umask = 022
nodaemon = false
nocleanup = false

[program:x]
directory = %(here)s/../
command = python file.py
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile = /appropriate-path/to/access.log

最佳答案

Python 输出被缓冲。设置environment variable PYTHONUNBUFFERED=1 supervisord.conf 将禁用缓冲并更快地显示日志消息:

[program:x]
environment = PYTHONUNBUFFERED=1

或添加 -u command-line switchpython 命令:

[program:x]
command = python -u file.py

或者,您可以显式刷新 sys.stdout 处理程序:

sys.stdout.flush()

在 python 3.3 及更高版本上,您可以添加 flush=True 参数让函数为您执行此操作:

print(something, flush=True)

关于python - supervisord 日志不显示我的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13934801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com