Subprocess - Getting INFO logs in stderr with no error message and returncode is 0
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at test.py's Popen call and test.sh's wal-g invocation; reproduce the command and compare stdout and stderr with the direct shell run. Read the Python 3.8 subprocess.Popen and communicate documentation, then establish whether wal-g intentionally writes INFO logs to stderr; a useful resolution would identify the source and expected stream behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100