How to use the wurlitzer.pipes function in wurlitzer

To help you get started, we’ve selected a few wurlitzer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github manodeep / Corrfunc / Corrfunc / utils.py View on Github external
>>> with sys_pipes():  # doctest: +SKIP
    ...    call_some_c_function()

    See the Wurlitzer package for usage of `wurlitzer.pipes()`;
    see also https://github.com/manodeep/Corrfunc/issues/157.
    '''

    kwargs = {'stdout':None if sys.stdout.isatty() else sys.stdout,
              'stderr':None if sys.stderr.isatty() else sys.stderr }

    # Redirection might break for any number of reasons, like
    # stdout/err already being closed/redirected.  We probably
    # prefer not to crash in that case and instead continue
    # without any redirection.
    try:
        with wurlitzer.pipes(**kwargs):
            yield
    except:
        yield
github sjdv1982 / seamless / seamless / graphs / compiled_transformer / executor.py View on Github external
result_arg = ffi.new(result_arg_name+" *")
args.append(result_arg)

def run():
    error_code = module.lib.transform(*args)
    if error_code != 0:
        return error_code, None
    if result_schema["type"] == "object":
        result = unpack_result_struct(args[-1], result_schema)
    elif result_schema["type"] == "array":
        result = unpack_result_array_struct(args[-1], result_schema)
    else:
        result = args[-1][0]
    return 0, result

with wurlitzer.pipes() as (stdout, stderr):
    error_code, result = run()
sys.stderr.write(stderr.read())
sys.stdout.write(stdout.read())
ARRAYS.clear()
if error_code != 0:
    raise SeamlessStreamTransformationError("Compiled transformer returned non-zero value: {}".format(error_code))
github sjdv1982 / seamless / seamless / core / execute.py View on Github external
def execute(name, code,
      injector, module_workspace,
      identifier, namespace,
      inputs, output_name, celltype, result_queue
    ):
    assert identifier is not None
    try:
        old_stdio = sys.stdout, sys.stderr
        stdout, stderr = FakeStdStream(sys.stdout), FakeStdStream(sys.stderr)
        sys.stdout, sys.stderr = stdout, stderr
        with wurlitzer.pipes() as (stdout2, stderr2):
            result = _execute(name, code,
                injector, module_workspace,
                identifier, namespace,
                inputs, output_name, celltype, result_queue
            )

        msg_code, msg = result
        if msg_code == 2: # SeamlessTransformationError, propagate
            result_queue.put((1, msg))
        elif msg_code in (1, 10):
            std = ""
            sout = stdout.read() + stdout2.read()
            sys.stdout, sys.stderr = old_stdio
            if len(sout):
                if not len(std):
                    std = "\n"

wurlitzer

Capture C-level output in context managers

MIT
Latest version published 5 months ago

Package Health Score

77 / 100
Full package analysis

Similar packages