Skip to main content

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

  1. 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'>
    
  2. 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)
    
  3. Press ctrl+D for the terminal that executes python usage_example.py. You'll see the following logs from the service.

    Preview

Motivation (for the author)

  1. Extending VSCode with dynamically added commands/key bindings.
  2. Starting a language runtime and managing the lifetime of its parser server.

Metadata

Release files for subproc-mgr 0.1.1

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

Built distribution (wheel)

Table of built distributions (wheels) for subproc-mgr 0.1.1
File Interpreter ABI Platform
subproc_mgr-0.1.1-py3-none-any.whl Python 3 none any Details

Release files / subproc_mgr-0.1.1-py3-none-any.whl

Download URL subproc_mgr-0.1.1-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3217570fbc1e7b933392e17d7765981624ff299adb5118c24614ea8011cdbdb
BLAKE2b-256 checksum
How to use checksums
5b9f32f0c9482c5118dca6f3ff34de6336618c38fb3c0ed3289886394cb67a08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1

1 release file

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