python / python/cpython

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

Đang mở
#99,821 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
558

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ lệnh gọi Popen trong test.py và lời gọi wal-g trong test.sh; tái hiện lệnh rồi so sánh stdout và stderr với lần chạy trực tiếp trong shell. Đọc tài liệu về subprocess.Popen và communicate của Python 3.8, sau đó xác định liệu wal-g có chủ ý ghi các log INFO vào stderr hay không; một hướng giải quyết hữu ích sẽ xác định nguồn và hành vi stream được kỳ vọng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
bash, python
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.