Skip to content

subprocess.run() failure under Linux when calling mpirun while MPI communicator open #132377

@heplesser

Description

@heplesser

Bug report

Bug description:

The following code throws a CalledProcessError under Linux (Ubuntu 24) but passed under macOS (15.4).
Using mpi4py here is not essential, any program calling MPI_Init() will do.

The code works as expected if one either calls MPI.finalize() before calling subprocess.run() or just run echo in the subprocess without wrapping it with mpirun.

I used OpenMPI 4.1.6 under Ubuntu and OpenMPI 5.0.7 under macOS.

import subprocess
from mpi4py import MPI

# Uncomment the next line and it works
# MPI.Finalize()

res = subprocess.run(["mpirun", "-np", "1",    # comment out "mpirun" ... and it works
                      "echo", "This is the subprocess"],
                     check=True, capture_output=True)

CPython versions tested on:

3.13, 3.12

Operating systems tested on:

Linux, macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions