Skip to main content

Iterator with timeout

Project description

python-timeout-iterator

timeout-iterator provides a timeout in iteration.

Python PyPI version codecov License

Installation

$ pip install timeout-iterator

Usage

without_terminate

without_terminate is a generator that it will not yield after the timeout, but it will not raise an exception.

from timeout_iterator import without_terminate
results = []
for i in without_terminate(range(10), seconds=0.3):
    results.append(i)
    time.sleep(0.1)

assert results == [0, 1, 2]

terminate

terminate is a generator that it will raise an exception after the timeout.

from timeout_iterator import terminate
try:
    results = []
    for i in terminate(range(10), seconds=0.3):
        results.append(i)
        time.sleep(0.1)
except TimeoutError:
    pass

assert results == [0, 1, 2]

LICENSE

BSD 3-Clause License

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

timeout_iterator-0.2.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

timeout_iterator-0.2.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file timeout_iterator-0.2.0.tar.gz.

File metadata

  • Download URL: timeout_iterator-0.2.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for timeout_iterator-0.2.0.tar.gz
Algorithm Hash digest
SHA256 85478d4ce4edfb6452e8a626aeba30d83eadf3e4ee706b6bcdf129ab1322120a
MD5 b59bcd9c139515263310104f71f1f46d
BLAKE2b-256 f97842c558e3b92a3699ab0e7fb14625242f470cae82b584de3f234e20fbdd20

See more details on using hashes here.

File details

Details for the file timeout_iterator-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for timeout_iterator-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 007111712b3f63a11cc74b301dd9b335e09a9a8ec1db92ba28a94e1497a4b615
MD5 ec01ddd8ec406bc4898cc44fc0234ab4
BLAKE2b-256 78b197f98755d4d6a0739ba66e7469f21a8affe8b30d882b1eba7628bbc6b6bb

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