python / python/cpython

Subprocess - Getting INFO logs in stderr with no error message and returncode is 0

未关闭
#99,821 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

I am using subprocess module to run some bash jobs. Here subprocess is not working expected as it is giving me INFO logs in its stderr object. There is no single log which show any error/exception message. I have tried by running the same bash job using terminal and I am not getting any error there too. Also the return code of the process is 0.

Here is the python code that I am using

backup_name = "base_000000010000000000000005"
time = datetime.utcnow()
file = "/test.sh"
arguments = [file, time.strftime('%Y-%m-%d %H:%M:%S'), backup_name]
proc = subprocess.Popen(arguments, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
print('returncode :{}'.format(proc.returncode))
if stderr:
    print("stderr :")
    print(stderr.decode())

test.sh

wal-g backup-fetch /new_directory $2

On executing the above code,

postgres@test-9:~/restoration$ python3 test.py 
returncode :0
stdout :Params: /vol/restore/postgresql/14/main, base_000000010000000000000005, 2022-11-25 11:20:20

stderr :
INFO: 2022/11/26 09:54:44.264085 Selecting the backup with name base_000000010000000000000005...
INFO: 2022/11/26 09:54:44.425420 Finished decompression of part_003.tar.lz4
INFO: 2022/11/26 09:54:44.425432 Finished extraction of part_003.tar.lz4
INFO: 2022/11/26 09:54:46.261901 Finished extraction of part_001.tar.lz4
INFO: 2022/11/26 09:54:46.261916 Finished decompression of part_001.tar.lz4
INFO: 2022/11/26 09:54:46.286092 Finished decompression of pg_control.tar.lz4
INFO: 2022/11/26 09:54:46.286104 Finished extraction of pg_control.tar.lz4
INFO: 2022/11/26 09:54:46.286108 
Backup extraction complete.

You can see in the above response, there is not a single which is giving any error information all are INFO logs. On executing the same scripts on the shell I got the same response, there is also not any error log.

postgres@test-9:~/restoration$ ./test.sh '2022-11-25 11:30' base_000000010000000000000005
INFO: 2022/11/26 09:54:23.148111 Selecting the backup with name base_000000010000000000000005...
INFO: 2022/11/26 09:54:23.303886 Finished decompression of part_003.tar.lz4
INFO: 2022/11/26 09:54:23.303939 Finished extraction of part_003.tar.lz4
INFO: 2022/11/26 09:54:25.144313 Finished extraction of part_001.tar.lz4
INFO: 2022/11/26 09:54:25.144327 Finished decompression of part_001.tar.lz4
INFO: 2022/11/26 09:54:25.163943 Finished decompression of pg_control.tar.lz4
INFO: 2022/11/26 09:54:25.163960 Finished extraction of pg_control.tar.lz4
INFO: 2022/11/26 09:54:25.163970 
Backup extraction complete.

Version : Python 3.8.10

I have tried by passing every possible argument in Popen, but getting the same response in stderr. Can I get help here, why the INFO logs are coming inside the stderr, as it should be NONE if there is no error.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 test.py 中的 Popen 调用和 test.sh 中的 wal-g 调用入手;重现该命令,并将 stdout 和 stderr 与直接在 shell 中运行的结果进行比较。阅读 Python 3.8 的 subprocess.Popen 和 communicate 文档,然后确定 wal-g 是否有意将 INFO 日志写入 stderr;有用的解决方案应明确其来源以及预期的流行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
bash, python
领域
operating-systems
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。