python / python/cpython

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

オープン
#99,821 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

test.py の Popen 呼び出しと test.sh の wal-g 呼び出しから始め、コマンドを再現して stdout と stderr をシェルから直接実行した場合と比較します。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 を短くまとめたダイジェスト。