Skip to main content

orphanage

Let child processes in Python suicide if they became orphans.

Installation

pip install orphanage

Don’t forget to put it in setup.py / requirements.txt.

Usage

from orphanage import exit_when_orphaned

exit_when_orphaned()

Motivation

Some application server softwares (e.g. Gunicorn) work on a multiple-process architect which we call the master-worker model. They must clean up the worker processes if the master process is stopped, to prevent them from becoming orphan processes.

In the gevent-integration scene, the worker processes of Gunicorn poll their ppid in an user thread (a.k.a greenlet) to be orphan-aware. But the user thread may be hanged once the master process crashed because of the blocked writing on a pipe, the communicating channel between master process and worker processes.

We want to perform this ppid polling in a real kernel thread. That is the intent of this library.

Principle

This library spawns an internal thread to poll the ppid at regular intervals (for now it is one second). Once the ppid changed, the original parent process should be dead and the current process should be orphaned. The internal thread will send SIGTERM to the current process.

In the plan, the prctl & SIGHUP pattern may be introduced in Linux platforms to avoid from creating threads. For now, the only supported strategy is the ppid polling, for being portable.

Alternatives

CaoE is an alternative to this library which developed by the Douban Inc. It uses prctl and a twice-forking pattern. It has a pure Python implementation without any C extension compiling requirement. If you don’t mind to twist the process tree, that will be a good choice too.

Contributing

If you want to report bugs or request features, please feel free to open issues on GitHub.

Of course, pull requests are always welcome.

Metadata

Release files for orphanage 0.1.0

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

Source distribution (sdist)

Source distribution for orphanage 0.1.0
File Size Uploaded Provenance
orphanage-0.1.0.tar.gz 6.5 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for orphanage 0.1.0
File
orphanage-0.1.0-pp3510-pypy3_510-macosx_10_13_x86_64.whl PyPy 3.510 PyPy 3 macOS 10.13+ x86-64 Details
orphanage-0.1.0-pp2510-pypy_41-macosx_10_13_x86_64.whl PyPy 2.510 PyPy 4.1 macOS 10.13+ x86-64 Details
orphanage-0.1.0-pp360-pypy3_60-manylinux1_x86_64.whl PyPy 3.60 PyPy 3 Linux glibc 2.5+ x86-64 Details
orphanage-0.1.0-pp260-pypy_41-manylinux1_x86_64.whl PyPy 2.60 PyPy 4.1 Linux glibc 2.5+ x86-64 Details
orphanage-0.1.0-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
orphanage-0.1.0-cp36-cp36m-macosx_10_13_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.13+ x86-64 Details
orphanage-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64 Details
orphanage-0.1.0-cp27-cp27m-macosx_10_13_x86_64.whl CPython 2.7 CPython 2.7 pymalloc macOS 10.13+ x86-64 Details

Total release size: 117.8 kB

Release files / orphanage-0.1.0.tar.gz

Download URL orphanage-0.1.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f5ae69e99fcdd7996e5ed6744477b5168c01b690009b84acd88e3be178578a6a
BLAKE2b-256 checksum
How to use checksums
33eba4b6c6120a0f61866e9aac47c98db02f8cf2e0ec19b0f21e91e669a4f991
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / orphanage-0.1.0-pp3510-pypy3_510-macosx_10_13_x86_64.whl

Download URL orphanage-0.1.0-pp3510-pypy3_510-macosx_10_13_x86_64.whl
Size 8.7 kB
Tags PyPy 3 PyPy 3.510 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
26a6b1515a6c22a1cbb73c48f009914f6d12f12380bb622deb02321eb44784cf
BLAKE2b-256 checksum
How to use checksums
3b947ec0548ffdf1b5048b85b5f208cde6054387bd5093f56ea63708a51dcd04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / orphanage-0.1.0-pp2510-pypy_41-macosx_10_13_x86_64.whl

Download URL orphanage-0.1.0-pp2510-pypy_41-macosx_10_13_x86_64.whl
Size 12.3 kB
Tags PyPy 2.510 PyPy 4.1 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
ce39ab1f79d73aec3825817bd50d1d353cd81cecf9986c7a4060a3912905c04e
BLAKE2b-256 checksum
How to use checksums
bacac73bd3f8fb986967af3dbca6f868d0da6857d4d43bb3f812509944d34c6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / orphanage-0.1.0-pp360-pypy3_60-manylinux1_x86_64.whl

Download URL orphanage-0.1.0-pp360-pypy3_60-manylinux1_x86_64.whl
Size 10.4 kB
Tags Linux glibc 2.5+ x86-64 PyPy 3 PyPy 3.60
SHA-256 checksum
How to use checksums
f6f45325a06c71972730f0ddacfc9cb3b9b59a1910ab7d917ad7a0d26f561e02
BLAKE2b-256 checksum
How to use checksums
214d881878574dcfb03d21e20f660cf790124e2333d6e6fb26de05a908bbd87c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / orphanage-0.1.0-pp260-pypy_41-manylinux1_x86_64.whl

Download URL orphanage-0.1.0-pp260-pypy_41-manylinux1_x86_64.whl
Size 23.6 kB
Tags Linux glibc 2.5+ x86-64 PyPy 2.60 PyPy 4.1
SHA-256 checksum
How to use checksums
0160915acc25c8bbbdb8c3a39400b9ec2325ec16608817c26e145eba1d81023b
BLAKE2b-256 checksum
How to use checksums
1070b1c4cc8459fd9f19522bacfaf7d194c2315b2db598d025eb8e885f3e9a33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / orphanage-0.1.0-cp36-cp36m-manylinux1_x86_64.whl

Download URL orphanage-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
Size 16.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
8d482ef8ff69fe72bf51fab9d0adbb42a08ed44cb2d68282f3e68cc6400ee47a
BLAKE2b-256 checksum
How to use checksums
e6206e0310ef8ec6b3d0e1d593da3183f764651d9415848c0155c2880d142d33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / orphanage-0.1.0-cp36-cp36m-macosx_10_13_x86_64.whl

Download URL orphanage-0.1.0-cp36-cp36m-macosx_10_13_x86_64.whl
Size 10.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
addef2e38475b23bb0b1698d831363a6b68eac3910d993d26cd4e44df6b15e6d
BLAKE2b-256 checksum
How to use checksums
5a4aca31ad8b3a85d31dc953a095935c4d39be66acc631a2af394dd319a8551b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / orphanage-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl

Download URL orphanage-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl
Size 19.7 kB
Tags CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
42fd846417ecd91d975b28d02d15d2e44ccd54605eb2511ff8219aa2a23b2f0f
BLAKE2b-256 checksum
How to use checksums
c20a3b7c291ccfc3ebf141dd1118313daae86fdfe77437b40e1c689adce0db36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / orphanage-0.1.0-cp27-cp27m-macosx_10_13_x86_64.whl

Download URL orphanage-0.1.0-cp27-cp27m-macosx_10_13_x86_64.whl
Size 10.1 kB
Tags CPython 2.7 CPython 2.7 pymalloc macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
072545a0f3537d9edd751b6742549013695dfccd83e3f8e41663f08b9383844f
BLAKE2b-256 checksum
How to use checksums
c59eac7a832ab42c9303f1ab357109048543f6dcb4b11ef3f2ff954fd35a8264
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for orphanage 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

9 release files No provenance

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