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

Uploaded Source

Built Distribution

wurlitzer-2.0.1-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: wurlitzer-2.0.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.6

File hashes

Hashes for wurlitzer-2.0.1.tar.gz
Algorithm Hash digest
SHA256 d08f0728a998441aac3d7a0f8cd6dfed2ba2525144878fb49599b719085b7543
MD5 fd43af106c1d064fe0a28f898a903bd5
BLAKE2b-256 022e56d35781ef9ca92e26ff1fb3f351615a70083a95085d56d47451860925c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wurlitzer-2.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.6

File hashes

Hashes for wurlitzer-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2b4f1a6b62660ccddb066a49cda3845f6583ed5ab70e22a0ccc0f741063945d8
MD5 68819d5b25f114da402dd4e488f76a1b
BLAKE2b-256 0c1e52f4effa64a447c4ec0fb71222799e2ac32c55b4b6c1725fccdf6123146e

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