subproc-mgr


Namesubproc-mgr JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/thautwarm/subproc_mgr
SummaryA service to spawn and manage long-running child processes, following the lifecycle management of "child processes are attached to parent processes".
upload_time2023-05-14 12:26:51
maintainer
docs_urlNone
authorthautwarm
requires_python>=3.9
licensemit
keywords subprocess lifetime
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

    ```shell
    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
    shell> cat usage_example.py
    shell> python usage_example.py
    ```

    ```python

    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](./static/preview.png)

## 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thautwarm/subproc_mgr",
    "name": "subproc-mgr",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "subprocess,lifetime",
    "author": "thautwarm",
    "author_email": "twshere@outlook.com",
    "download_url": "",
    "platform": "any",
    "description": "# subproc_mgr\n\n## Motivation\n\nApplications 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).\n\nThis 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.\n\nP.S: This approach could be better (easier and cheaper) than a watchdog if you have a consensus conventions on how to spawn subprocesses.\n\n## Usage\n\n1. The service should be started:\n\n    ```shell\n    usage: subproc_mgr [-h] [--port PORT] [--period PERIOD] [port] [period]\n\n\n        port: port that the service is deployed on\n        period: how often the service checks the lifetime of subprocesses\n\n\n    positional arguments:\n        port             <class 'int'>\n        period           <class 'float'>\n\n    options:\n        -h, --help       show this help message and exit\n        --port PORT      <class 'int'>\n        --period PERIOD  <class 'float'>\n    ```\n\n2. We send requests (e.g., HTTP requests) to use the service:\n\n    ```shell\n    shell> cat usage_example.py\n    shell> python usage_example.py\n    ```\n\n    ```python\n\n    from typing import TypedDict\n    import requests, os, shutil\n\n    PORT = 5687\n\n    class StartProcessRequest(TypedDict):\n        command: str\n        args: list[str]\n        env: dict[str, str]\n        pid: int\n\n    # start python -m http.server\n    resp = requests.post(\n        f\"http://localhost:{PORT}/spawn\",\n        json=StartProcessRequest(\n            command=shutil.which(\"python\") or \"python\",\n            args=['-m', 'http.server'],\n            env=dict(os.environ),\n            pid=os.getpid()\n        )\n    )\n\n    assert resp.json().get(\"code\") == \"success\"\n\n    # press Ctrl+D, the subprocess exits very sooner\n    while True:\n        import time\n        time.sleep(0.5)\n    ```\n\n3. Press ctrl+D for the terminal that executes `python usage_example.py`. You'll see the following logs from the service.\n\n    ![Preview](./static/preview.png)\n\n## Motivation (for the author)\n\n1. Extending VSCode with dynamically added commands/key bindings.\n2. Starting a language runtime and managing the lifetime of its parser server.\n",
    "bugtrack_url": null,
    "license": "mit",
    "summary": "A service to spawn and manage long-running child processes, following the lifecycle management of \"child processes are attached to parent processes\".",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/thautwarm/subproc_mgr"
    },
    "split_keywords": [
        "subprocess",
        "lifetime"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b9f32f0c9482c5118dca6f3ff34de6336618c38fb3c0ed3289886394cb67a08",
                "md5": "45ae8c1519a4c311d18262f8f63ed798",
                "sha256": "e3217570fbc1e7b933392e17d7765981624ff299adb5118c24614ea8011cdbdb"
            },
            "downloads": -1,
            "filename": "subproc_mgr-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "45ae8c1519a4c311d18262f8f63ed798",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 5280,
            "upload_time": "2023-05-14T12:26:51",
            "upload_time_iso_8601": "2023-05-14T12:26:51.081714Z",
            "url": "https://files.pythonhosted.org/packages/5b/9f/32f0c9482c5118dca6f3ff34de6336618c38fb3c0ed3289886394cb67a08/subproc_mgr-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-14 12:26:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thautwarm",
    "github_project": "subproc_mgr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "subproc-mgr"
}
        
Elapsed time: 0.07673s