Skip to main content

Run a process and log stdin and stdout.

Project description

logproc

Run a process and live log stdin and stdout.

Description

This experimental module allows you to run an external program in the background and to live capture and handle its standard output and standard error.

Each captured line of output is immediately forwarded to the logging system (or whatever handler you provide) so that you can immediately see the output if you are logging to console. Both an asynchronous and a synchronous API is provided.

Basic Usage

In the simplest case, just run execute(["ls", "-l"]), which will run ls -l and log its output with Python’s default logging system, using the logger id ls and the level INFO for stdout, WARNING for stderr.

If you already run an asynchronous event loop, you can use the asynchronous API by running await aexecute(["ls", "-l"]) instead.

For more details, see the API reference

Launching processes in parallel

Sometimes it is useful to launch multiple processes in parallel and capture their output as it appears, while still limiting the number of concurrent processes (e.g., to the number of available CPU cores). This is possible using map_unordered. E.g.,

async def render_graphs(folder: Path):
    commands = (["dot", "-Tsvg", "-o", fspath(file.with_suffix(".svg")), fspath(file)] 
                for file in folder.glob("*.dot"))
    async for result in map_unordered(aexecute, commands):
        # Process the result
        pass

calls dot for each *.dot file in the given folder, limiting the number of concurrent jobs to the number of available CPU cores.

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

logproc-0.3.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logproc-0.3.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file logproc-0.3.0.tar.gz.

File metadata

  • Download URL: logproc-0.3.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for logproc-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2aeeecf67c16190df4c81e1e24353fda50350044ab60cf5edc6d1fdfd9fc9227
MD5 40645fd18a44ac411b8137cc2c50c767
BLAKE2b-256 88799332b471ffee6ce2c3b63215977599c89d6dc1c8691fd3633f3438882b39

See more details on using hashes here.

File details

Details for the file logproc-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: logproc-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for logproc-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13a08f38b8d93292c985c797f3537889c8a4be9108c73c7a5ca54fe0b2ba68de
MD5 d2fe0b5fb6a7ee5fc9b70e845fafd892
BLAKE2b-256 4c12095b2d0f7507e132cdbb3c2d0ca60d284ae0fe615ae2a8bf9aefa064a1d7

See more details on using hashes here.

Supported by

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