Skip to main content

Non blocking io wrapper over an input stream

Project description

non_blocking_io_wrapper

Description:

non_blocking_io_wrapper.NonBlockingReader is a wrapper class to build a non blocking stream from any read stream. It can be used for example to wrap the stdout pipe of a subprocess in a non blocking way.

It is a true io.RawIOBase subclass. Because of that, any method valid on an input byte stream should work seamlessly. Yet, a line access (readline, or iterator) will raise an OSError if no data is available at call time (you can use the select method to test/wait for that condition). If some data is available a line will be returned, or a partial one if no newline is available in the buffer.

If no data is present, a read will return None instead of blocking.

Additional methods

drain(timeout=None)

Waits for the underlying stream to reach its end of file.

If timeout is given and is not None it is the maximum time in seconds to wait.

Returns True if it succeeded or False on timeout.

It is intended to force a blocking wait after signaling an end of communication to a peer.

select(timeout=None)

Waits for data to become available.

If timeout is given and is not None it is the maximum time in seconds to wait.

Returns True if it succeeded or False on timeout

It is intended to allow to wait for availability of some data.

Installation

From PyPI

Released version are normally available from PyPI. Just user pip to install the last one:

pip install non_blocking_io_wrapper

From GitHUB

You can also clone the main repository from GitHUB:

git clone https://github.com/s-ball/non_blocking_io_wrapper.git

Contribution - development

A test package (97% coverage as of 0.5) is included in the GitHUB repository and in the source packages on PyPI.

Special processing for version.py

Versioning file is not included in the GitHUB repository because it is generated with setuptools_scm. It is of course included in PyPI packages so you should make sure to have a true git repository, or to get the sources from PyPI. The symptom is that you get a version number of 0.0.0 ...

Disclaimer: beta quality

It is fully functional and pass tests for Python 3.6 to 3.9 on Travis-CI. Yet it could have a better documentation, and has not been extensively tested.

License

This work is licenced under a MIT Licence. See LICENSE.txt

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

non_blocking_io_wrapper-0.7.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

non_blocking_io_wrapper-0.7.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file non_blocking_io_wrapper-0.7.0.tar.gz.

File metadata

  • Download URL: non_blocking_io_wrapper-0.7.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.4

File hashes

Hashes for non_blocking_io_wrapper-0.7.0.tar.gz
Algorithm Hash digest
SHA256 36e5f9e47eb0250324570a30366343d4a8a560131752b6a4710752d6b76a8106
MD5 fd9a9886f85294fa9154ae242e7ba3b4
BLAKE2b-256 fd1b0c3083a1cbf26f6314f9406828e8eedd85c40ca88b962f70ceb2372c898c

See more details on using hashes here.

File details

Details for the file non_blocking_io_wrapper-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: non_blocking_io_wrapper-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.4

File hashes

Hashes for non_blocking_io_wrapper-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d306acf288616fb037fbe69950aaa635b975fe32377926c6cbc2dfbcf12d2c18
MD5 ab2100c658bebbe7360852d525d052c0
BLAKE2b-256 d4d24adf4596ec5a2301333a3cb638690a333ed708135c71cffff7fadadf898d

See more details on using hashes here.

Supported by

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