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.1.1.tar.gz (15.9 kB view hashes)

Uploaded Source

Built Distribution

timeout_iterator-0.1.1-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

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