Skip to main content

Let orphan processes suicide

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orphanage-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distributions

orphanage-0.1.0-pp3510-pypy3_510-macosx_10_13_x86_64.whl (8.7 kB view details)

Uploaded PyPy macOS 10.13+ x86-64

orphanage-0.1.0-pp2510-pypy_41-macosx_10_13_x86_64.whl (12.3 kB view details)

Uploaded PyPy macOS 10.13+ x86-64

orphanage-0.1.0-cp36-cp36m-manylinux1_x86_64.whl (16.7 kB view details)

Uploaded CPython 3.6m

orphanage-0.1.0-cp36-cp36m-macosx_10_13_x86_64.whl (10.1 kB view details)

Uploaded CPython 3.6m macOS 10.13+ x86-64

orphanage-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl (19.7 kB view details)

Uploaded CPython 2.7mu

orphanage-0.1.0-cp27-cp27m-macosx_10_13_x86_64.whl (10.1 kB view details)

Uploaded CPython 2.7m macOS 10.13+ x86-64

File details

Details for the file orphanage-0.1.0.tar.gz.

File metadata

  • Download URL: orphanage-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for orphanage-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f5ae69e99fcdd7996e5ed6744477b5168c01b690009b84acd88e3be178578a6a
MD5 7cc52d80eea23a93fb67fcd864c16e57
BLAKE2b-256 33eba4b6c6120a0f61866e9aac47c98db02f8cf2e0ec19b0f21e91e669a4f991

See more details on using hashes here.

File details

Details for the file orphanage-0.1.0-pp3510-pypy3_510-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for orphanage-0.1.0-pp3510-pypy3_510-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 26a6b1515a6c22a1cbb73c48f009914f6d12f12380bb622deb02321eb44784cf
MD5 f8604f40c5b713b5d2a4964f0d38450b
BLAKE2b-256 3b947ec0548ffdf1b5048b85b5f208cde6054387bd5093f56ea63708a51dcd04

See more details on using hashes here.

File details

Details for the file orphanage-0.1.0-pp2510-pypy_41-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for orphanage-0.1.0-pp2510-pypy_41-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 ce39ab1f79d73aec3825817bd50d1d353cd81cecf9986c7a4060a3912905c04e
MD5 9bb7e75686e202cc8291de5d9d9c232a
BLAKE2b-256 bacac73bd3f8fb986967af3dbca6f868d0da6857d4d43bb3f812509944d34c6d

See more details on using hashes here.

File details

Details for the file orphanage-0.1.0-pp360-pypy3_60-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for orphanage-0.1.0-pp360-pypy3_60-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f6f45325a06c71972730f0ddacfc9cb3b9b59a1910ab7d917ad7a0d26f561e02
MD5 defc8e74720d27a19312a0a58b370717
BLAKE2b-256 214d881878574dcfb03d21e20f660cf790124e2333d6e6fb26de05a908bbd87c

See more details on using hashes here.

File details

Details for the file orphanage-0.1.0-pp260-pypy_41-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for orphanage-0.1.0-pp260-pypy_41-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0160915acc25c8bbbdb8c3a39400b9ec2325ec16608817c26e145eba1d81023b
MD5 029bfdd291c78c29052dcebce8b871c0
BLAKE2b-256 1070b1c4cc8459fd9f19522bacfaf7d194c2315b2db598d025eb8e885f3e9a33

See more details on using hashes here.

File details

Details for the file orphanage-0.1.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for orphanage-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8d482ef8ff69fe72bf51fab9d0adbb42a08ed44cb2d68282f3e68cc6400ee47a
MD5 3404c833515951424af393073e64caab
BLAKE2b-256 e6206e0310ef8ec6b3d0e1d593da3183f764651d9415848c0155c2880d142d33

See more details on using hashes here.

File details

Details for the file orphanage-0.1.0-cp36-cp36m-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for orphanage-0.1.0-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 addef2e38475b23bb0b1698d831363a6b68eac3910d993d26cd4e44df6b15e6d
MD5 f6fff952c780955840463b2ef8aecae1
BLAKE2b-256 5a4aca31ad8b3a85d31dc953a095935c4d39be66acc631a2af394dd319a8551b

See more details on using hashes here.

File details

Details for the file orphanage-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for orphanage-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 42fd846417ecd91d975b28d02d15d2e44ccd54605eb2511ff8219aa2a23b2f0f
MD5 7615280a94ca87d7914729c9c4d132ab
BLAKE2b-256 c20a3b7c291ccfc3ebf141dd1118313daae86fdfe77437b40e1c689adce0db36

See more details on using hashes here.

File details

Details for the file orphanage-0.1.0-cp27-cp27m-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for orphanage-0.1.0-cp27-cp27m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 072545a0f3537d9edd751b6742549013695dfccd83e3f8e41663f08b9383844f
MD5 a18550dd6b4c0637955f573cc997b47d
BLAKE2b-256 c59eac7a832ab42c9303f1ab357109048543f6dcb4b11ef3f2ff954fd35a8264

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page