streamcapture | Capture the outputs of Python streams , such as sys.stdout

 by   sloisel Python Version: 1.2.4 License: MIT

kandi X-RAY | streamcapture Summary

kandi X-RAY | streamcapture Summary

streamcapture is a Python library. streamcapture has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can install using 'pip install streamcapture' or download it from GitHub, PyPI.

Capture the outputs of Python streams, such as sys.stdout and sys.stderr
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              streamcapture has a low active ecosystem.
              It has 1 star(s) with 0 fork(s). There are 1 watchers for this library.
              There were 2 major release(s) in the last 6 months.
              streamcapture has no issues reported. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of streamcapture is 1.2.4

            kandi-Quality Quality

              streamcapture has no bugs reported.

            kandi-Security Security

              streamcapture has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              streamcapture is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              streamcapture releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of streamcapture
            Get all kandi verified functions for this library.

            streamcapture Key Features

            No Key Features are available at this moment for streamcapture.

            streamcapture Examples and Code Snippets

            No Code Snippets are available at this moment for streamcapture.

            Community Discussions

            No Community Discussions are available at this moment for streamcapture.Refer to stack overflow page for discussions.

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install streamcapture

            You can install using 'pip install streamcapture' or download it from GitHub, PyPI.
            You can use streamcapture like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            Class StreamCapture(stream, writer, echo=True, monkeypatch=None) is able to capture, at the operating system level, the data being written to the given stream. A typical use is to capture all outputs to sys.stdout and sys.stderr and log them to a file. This will even capture the outputs of spawned shell commands. StreamCapture works by essentially using os.dup2 to send stream.fileno() to a os.pipe(). A separate thread is used to listen to that os.pipe and send the outputs to the destination writer stream. StreamCapture also uses os.dup to duplicate the original filedescriptor to be able to restore it at the end. This duplicated filedescriptor is stored in StreamCapture.dup_fd, and writing to this filedescriptor results in writing to the original file, before it was redirected. For example, when redirecting sys.stdout, one can still write to the terminal by writing directly to StreamCapture.dup_fd with os.write(). On Windows, sys.stdout and sys.stderr do not take kindly to their fileno() being redirected with os.dup2. StreamCapture features an optional workaround, enabled by the monkeypatch optional parameter to the constructor. When enabled, the workaround overwrites stream.write(...) by an implementation that sends everything to os.write(self.fd,...). This workaround is enabled when monkeypatch=True and disabled when monkeypatch=False. The default is monkeypatch=None, in which case monkeypatching is enabled only when platform.system()=='Windows'. When writing to multiple streams and file descriptors, sometimes the order in which the writes appear can be surprising. For example, when writing to stderr and stdout, these outputs do not necessarily appear in the order in which they occurred during the program execution, because of various levels of buffering that occur in Python, the C library or the operating system. At the Python level, streams can be flush()ed to attempt to reduce the delay before a write() has delivered its payload. Furthermore, os.fsync() can be used on some, but not all, file descriptors. However, os.fsync() usually causes an exception if it is called on sys.stdout.fileno() or on a os.pipe(). In principle, the operating system should promtly flush any buffers when a file descriptor is os.close()d, but there is no guarantee. To complicate matters, although one usually prefers minimal buffering for outputs that go to the console, Python tries very hard to force some sort of buffering on text-mode files. We have tried to prevent most forms of buffering at the Python level and at the operating system levels, but when multiple file descriptors are used, or at the boundary when a StreamCapture starts or stops capturing the underlying stream, some outputs that go to the console may appear in an unexpected order. More sophisticated behaviors can be handled by implementing a custom stream-like object. The writer object should implement functions writer.write(data), where data is a byte string, and writer.close(). The echo flag can be set at construction time StreamCapture(...,echo=True) and defaults to True. In this mode, all captured outputs are sent both to the writer and also to StreamCapture.dup_fd. This allows one to send, e.g. stdout to a log file while simultaneously printing it to the console, similar to the tee console command in Unix. The echo flag can be set to False to disable this. One can call StreamCapture.close() to cleanly unwind the captured streams. This is automatically done if StreamCapture is used in a with block. One may also wish to capture a filedescriptor without the overhead of a wrapping Python stream. To that end, one may use FDCapture(fd,writer,echo=True). The parameter fd is an integer filedescriptor to be captured. StreamCapture is a thin wrapper around FDCapture, it mainly adds the monkeypatching capability. streamcapture.Writer is a thin wrapper around an underlying stream, that allows sharing a stream between multiple threads in a thread-safe manner, guaranteeing that the underlying stream is closed only when all threads have called close. Writer objects are constructed by streamcapture.Writer(stream,count,lock_write = False). stream: is a stream that is being wrapped, e.g. stream = open('logfile.txt','wb'). count: is the number of times that Writer.close() will be called before the writer is finally closed. This is so that a single stream can be used from multiple threads. lock_write: set this to True if you want calls to stream.write() to be serialized. This causes Writer.write to acquire Writer.lock before calling stream.write. If lock_write=False then Writer.lock is not acquired. Use this when stream.write is thread-safe. lock_write=False is the default. In the above example, writer will be closed twice: once from the StreamCapture(sys.stdout,...) object, and once from the StreamCapture(sys.stderr,...) object. Correspondingly, the count parameter of the streamcapture.Writer was set to 2, so that the underlying stream is only closed after 2 calls to writer.close().
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install streamcapture

          • CLONE
          • HTTPS

            https://github.com/sloisel/streamcapture.git

          • CLI

            gh repo clone sloisel/streamcapture

          • sshUrl

            git@github.com:sloisel/streamcapture.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link