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

Uploaded Source

Built Distribution

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

timeout_iterator-0.2.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: timeout_iterator-0.2.1.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for timeout_iterator-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3c47266d8d4043fe79fd31dd0f02b0e6a67f1c505edba1d8e54db94da3e90b62
MD5 c299b0a5fa0e17e9209e7d9d0633562a
BLAKE2b-256 29e27901988dea2c8db0489181b4f9e8a7dd151a6bbbc0ed69f02813cd164778

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for timeout_iterator-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2fd3aa8820dd0af82f454f25e6e784c132054233a47eb42ba156bcd39b90f333
MD5 a0b1573e3c7572d680dc3dd51ffe3230
BLAKE2b-256 277f560913b8926251f2c82a87877e4d3bf0afb43593b1aef9c5da1784d56038

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