python / python/cpython

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

Ouverte
#99,821 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

stdlib type-bug
Langage dominant
Python
Étoiles
77.2k
Forks
36k
Métriques de merge des PR
Métriques de PR en attente

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par l’appel à Popen de test.py et l’invocation de wal-g dans test.sh ; reproduisez la commande et comparez stdout et stderr avec l’exécution directe dans le shell. Lisez la documentation de Python 3.8 sur subprocess.Popen et communicate, puis déterminez si wal-g écrit intentionnellement les journaux INFO sur stderr ; une résolution utile identifierait la source et le comportement attendu des flux.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
bash, python
Domaine
operating-systems
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.