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.1.tar.gz (4.8 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.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logproc-0.3.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","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.1.tar.gz
Algorithm Hash digest
SHA256 c7e0ca7a6851801785298bf33b4d1db418f7a5de423ab52939cb292dfb0eed73
MD5 1375fbad03110e9846fcaa4dfa34b246
BLAKE2b-256 daf612c6240655763b88c0a8a83ae75da20c2b0a77209cbe6a196d2a165e5552

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logproc-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35571324f3570a0819ec9c2ce938ff9bcde21c79abd67d7fbcbf166cfbab4ae7
MD5 5ec1a047cda3135cb86e47cfe2f33d65
BLAKE2b-256 d8c4114f68e29947ccad64ec3aa5914bd8dd2586ca6c5ad06e293e87960feb7d

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