Skip to main content

Capture C-level output in context managers

Project description

Wurlitzer

Capture C-level stdout/stderr pipes in Python via os.dup2.

For more details on why this is needed, please read this blog post.

Install

pip install wurlitzer

Usage

Capture stdout/stderr in pipes:

from wurlitzer import pipes

with pipes() as (out, err):
    call_some_c_function()

stdout = out.read()

Capture stdout/stderr in StringIO:

from io import StringIO
from wurlitzer import pipes, STDOUT

out = StringIO()
with pipes(stdout=out, stderr=STDOUT):
    call_some_c_function()

stdout = out.getvalue()

Forward C-level stdout/stderr to Python sys.stdout/stderr, which may already be forwarded somewhere by the environment, e.g. IPython:

from wurlitzer import sys_pipes

with sys_pipes():
    call_some_c_function()

Or even simpler, enable it as an IPython extension:

%load_ext wurlitzer

To forward all C-level output to IPython during execution.

Acknowledgments

This package is based on stuff we learned with @takluyver and @karies while working on capturing output from the Cling Kernel for Jupyter.

Wurlitzer?!

Wurlitzer makes pipe organs. Get it? Pipes? Naming is hard.

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

wurlitzer-2.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

wurlitzer-2.1.0-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wurlitzer-2.1.0.tar.gz.

File metadata

  • Download URL: wurlitzer-2.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for wurlitzer-2.1.0.tar.gz
Algorithm Hash digest
SHA256 0144228960a992ef46e339e8aa560600bd34cd64e018bfebad88c0dd61bd8ba5
MD5 dffa47f8c65bb2d5264b62a106f3c805
BLAKE2b-256 77882775689c67bf78248161cdfd2111726d11f0fc78c6d015dc98ce1299f560

See more details on using hashes here.

File details

Details for the file wurlitzer-2.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: wurlitzer-2.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for wurlitzer-2.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2272de20311055779f005a34246834ff97685948932b6418b33939e90dc30bff
MD5 8d917021153aad9cbf8857f685b4a262
BLAKE2b-256 68acb7082c3d228e600af37ec5cf99697d400328b13350b4d7577c213fa4faca

See more details on using hashes here.

Supported by

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