watchpid
watchpid is a tiny stdlib-only package for waiting until a process exits.
It uses OS process notifications when Python exposes them:
- Linux:
os.pidfd_open() - macOS/BSD:
select.kqueue() - Other platforms: polling fallback
Usage
Block until a pid exits:
from watchpid import wait_pid
if wait_pid(1234, timeout=5):
print("exited")
Run a callback in a daemon thread:
from watchpid import watch_pid
watch_pid(1234, lambda: print("exited"))
Watch the parent pid set by jupyter_client:
from watchpid import watch_parent
watch_parent(lambda: print("parent exited"))
watch_parent() reads JPY_PARENT_PID by default. It returns None when the env var is unset, invalid, or <= 1 (so pid 1/init is never watched).
Caveats
- The event-based backends (
pidfd,kqueue) detect exit reliably. The polling fallback uses pid liveness checks, so it is best-effort: it can't distinguish a reused pid, and an unreaped child process stays "alive" to the poller until it'swait()ed.
API
wait_pid(pid, timeout=None, poll=0.1) -> bool
watch_pid(pid, callback, timeout=None, poll=0.1, daemon=True, name=None) -> Thread
parent_pid(env="JPY_PARENT_PID") -> int | None
watch_parent(callback, env="JPY_PARENT_PID", timeout=None, poll=0.1, daemon=True, name="watchpid-parent") -> Thread | None
wait_pid() returns True when the process exits and False on timeout.
Development
pip install -e ".[test]"
pytest -q
Metadata
Release files for watchpid 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| watchpid-0.1.1.tar.gz | 8.4 kB | Without provenance | Details for watchpid-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| watchpid-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for watchpid-0.1.1-py3-none-any.whl |
Total release size: 16.3 kB
Release files / watchpid-0.1.1.tar.gz
| Download URL | watchpid-0.1.1.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53cba3648cbbae9e02aaae0862d38d118e1d46f6f9cf049d3cb27f156f4bd7c3
|
|
BLAKE2b-256 checksum How to use checksums |
b4bbfdb206894fdc337c3b5b57893aebcb644c0c78b6af8c8430d3dc45ba327e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / watchpid-0.1.1-py3-none-any.whl
| Download URL | watchpid-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2325efeccb0dadea2c39de09c83cc54b5c003eba2e9d49e4c9d6ebbb5960b8e
|
|
BLAKE2b-256 checksum How to use checksums |
8e4886a11703feb912b9b933b5b0bd77da54d9d13223e27799923cdfc77ba602
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Security for watchpid 0.1.1
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.