我有一个python子进程,我正在尝试从中读取输出和错误流.目前我有它的工作,但我只能在读完stderr之后阅读stdout.这是它的样子:
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout_iterator = iter(process.stdout.readline, b"")
stderr_iterator = iter(process.stderr.readline, b"")
for line in stdout_iterator:
# Do stuff with line
print line
for line in stderr_iterator:
# Do stuff with line
print line
Run Code Online (Sandbox Code Playgroud)
如您所见,stderrfor循环在stdout循环完成之前无法启动.如何修改它以便能够以正确的顺序读取这两行?
澄清:我仍然需要能够判断一条线是否来自stdout或者stderr因为我的代码中它们的处理方式不同.
我正在通过Kuberenetes部署Google Cloud上的容器,这些是django项目和uwsgi来运行它们.
我正在使用stackdrive日志工具来查看日志记录,问题是所有条目都被视为严重性,ERROR即使它们不是错误.似乎uwsgi写入的日志stderr或类似的东西.
在图片中你可以看到django使用了INFOlevel,但是这是ERROR通过stackdrive 接收的.
这就是我设置uwsgi的方式.
[uwsgi]
master = true
socket = :3031
chdir = .
wsgi-file = docker.wsgi
processes = 4
threads = 2
socket-timeout = 90
harakiri = 90
http = :8000
env = prometheus_multiproc_dir=multi
enable-threads = yes
lazy-apps = yes
pidfile=/tmp/project-master.pid