A service to spawn and manage long-running child processes, following the lifecycle management of "child processes are attached to parent processes".
Project description
subproc_mgr
Motivation
Applications that spawn long-running subprocesses need to be able to manage the lifetime of those subprocesses, which is so-far not a truth as the application can exit unexpectedly (e.g., runtime, or buggy high-level software).
This is a simple service that can be deployed globally that proxies subprocess spawning and manages the lifetime. The service will periodically check the lifetime of the subprocesses and kill them if they have exceeded the expected lifetime.
P.S: This approach could be better (easier and cheaper) than a watchdog if you have a consensus conventions on how to spawn subprocesses.
Usage
-
The service should be started:
usage: subproc_mgr [-h] [--port PORT] [--period PERIOD] [port] [period] port: port that the service is deployed on period: how often the service checks the lifetime of subprocesses positional arguments: port <class 'int'> period <class 'float'> options: -h, --help show this help message and exit --port PORT <class 'int'> --period PERIOD <class 'float'>
-
We send requests (e.g., HTTP requests) to use the service:
shell> cat usage_example.py shell> python usage_example.py
from typing import TypedDict import requests, os, shutil PORT = 5687 class StartProcessRequest(TypedDict): command: str args: list[str] env: dict[str, str] pid: int # start python -m http.server resp = requests.post( f"http://localhost:{PORT}/spawn", json=StartProcessRequest( command=shutil.which("python") or "python", args=['-m', 'http.server'], env=dict(os.environ), pid=os.getpid() ) ) assert resp.json().get("code") == "success" # press Ctrl+D, the subprocess exits very sooner while True: import time time.sleep(0.5)
-
Press ctrl+D for the terminal that executes
python usage_example.py
. You'll see the following logs from the service.
Motivation (for the author)
- Extending VSCode with dynamically added commands/key bindings.
- Starting a language runtime and managing the lifetime of its parser server.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file subproc_mgr-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: subproc_mgr-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3217570fbc1e7b933392e17d7765981624ff299adb5118c24614ea8011cdbdb |
|
MD5 | 45ae8c1519a4c311d18262f8f63ed798 |
|
BLAKE2b-256 | 5b9f32f0c9482c5118dca6f3ff34de6336618c38fb3c0ed3289886394cb67a08 |