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

Abierto
#96,863 5 comentarios 0 reacciones 2 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

stdlib topic-subprocess type-bug

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
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Merge medio
1 d 9 h
PR fusionados (30 d)
558

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python/cpython

Todos los issues de python/cpython

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.