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-1.0.3.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

wurlitzer-1.0.3-py2.py3-none-any.whl (6.0 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: wurlitzer-1.0.3.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for wurlitzer-1.0.3.tar.gz
Algorithm Hash digest
SHA256 f972c329da26e397b06a3f85be06145a47fb5d3fe138a83d84bde1e76e214b59
MD5 43d53e89938c08212fda7f0c2501fb96
BLAKE2b-256 5e54aeb3e6d47afbe5f8813c5d2d7615151139f6fcfc71110f8adfbb716f9fd7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wurlitzer-1.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for wurlitzer-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ff003138adc22212f1921cfa3b1bff7bf5a583d9ae0602819bf1a34f31aabfad
MD5 daa29b141b0318665917679b8437681f
BLAKE2b-256 0956201c4d13c37b6fb0cb5dbf1d026a2fec14fd151fd4f3f1dc1144d6273fd3

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