python / python/cpython

Incorrect exit status of an already waited process in subprocess.Popen

Ouverte
#96,863 5 commentaires 0 réactions 2 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

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

Description

Bug report

If a process run by subprocess.Popen and its exit status is obtained by os.wait() or os.waitpid(), then calling the wait() method on the Popen object always returns zero.

Example:

import os
import subprocess

proc = subprocess.Popen(["false"]) # could be any process with non-zero exit status
pid, status = os.wait()
print("status from os.wait()", status)  # prints non-zero exit status correctly
print("status from proc.wait()", proc.wait()) # prints zero exit status incorrectly

The root cause of the problem is that the child has been already wait()ed, so the Popen object has no chance to obtain the exit code as the process no longer exists. It calls waitpid() here but it ignores ECHILD and defaults the status to zero.

Your environment

  • CPython versions tested on: Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux
  • Operating system and architecture: Linux x86-64
Linked PRs
  • gh-137804

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.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

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