Skip to main content

pyreap

This module provides a subprocess.Popen()-compatible reap.Popen() function that has the nice property that if the parent process dies the child process will also be reaped.

Normally, orphaned child processes will end up re-parented to the init(1) process and then live on until they finally complete of their own volition. This often (usually?) isn’t the desired behavior and it can be really handy to ensure that when a parent process dies all the child processes will be automatically cleaned up.

The reap module accomplishes this by inserting a small intermediate process between the parent and the child. This intermediate process periodically checks to see if its parent PID has changed (indicating that the parent died and we have been reparented to init(1) or some other init(1)-like process), and if a change is detected then it kills the child before itself exiting. This ensures that any child processes you create will not later live on as orphaned processes.

Using pyreap is as easy as using subprocess.Popen(), and in fact all arguments are simply passed to subprocess.Popen(); the reap.Popen() function also returns a subprocess.Popen object that you can use just like you normally would.

The following demonstrates how subprocess.Popen() behaves with an orphaned process (note the orphaned ‘sleep 1000’ lives on even after the Python interpreter has closed):

~$ python3
Python 3.8.5 (default, Jul 21 2020, 10:48:26)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.Popen(['/usr/bin/env', 'sleep', '1000'])
<subprocess.Popen object at 0x10fc67d30>
>>>
~$ ps aux | grep sleep
greent7          85310   0.0  0.0  4268280    656 s026  S+    4:57pm   0:00.01 grep sleep
greent7          85308   0.0  0.0  4268156    504 s026  S     4:57pm   0:00.01 sleep 1000

The following demonstrates how reap.Popen() solves the orphan issue:

greent7@avocado:~$ python3
Python 3.8.5 (default, Jul 21 2020, 10:48:26)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import reap
>>> reap.Popen(['/usr/bin/env', 'sleep', '1000'])
<subprocess.Popen object at 0x10bac9d30>
>>>
greent7@avocado:~$ ps aux | grep sleep
greent7          85319   0.0  0.0  4287736    704 s026  S+    4:57pm   0:00.01 grep sleep

Note how the ‘sleep 1000’ process is reaped after the Python interpreter shuts down.

Metadata

Release files for pyreap 0.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyreap 0.9.2
File Size Uploaded Provenance
pyreap-0.9.2.tar.gz 4.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyreap 0.9.2
File Interpreter ABI Platform
pyreap-0.9.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.3 kB

Release files / pyreap-0.9.2.tar.gz

Download URL pyreap-0.9.2.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9fa5099608e6990480f0f9fd6af6a2c8a8a790fb96f84b0c81121f8471575322
BLAKE2b-256 checksum
How to use checksums
9a9c94966683e0f9f2221a49e5f884199ee44fc0e64daad7a72ec270632e249c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / pyreap-0.9.2-py3-none-any.whl

Download URL pyreap-0.9.2-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ef856aaa9b20ffd3c523515b07063c8cd2937843d5b087117bb6db5a453cd0e
BLAKE2b-256 checksum
How to use checksums
70df26da0664baca8ca9f1c72f1b6e2bc3acf6f799629eeec8801cf1d7d7e802
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for pyreap 0.9.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page