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.2.tar.gz (31.2 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.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: timeout_iterator-0.2.2.tar.gz
  • Upload date:
  • Size: 31.2 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.2.tar.gz
Algorithm Hash digest
SHA256 08198cc131e9ea29e04515b4789799e809ebcd00c140a785eee3fcccc7e87ce1
MD5 d35df4117c482def4f8a6c55a355c967
BLAKE2b-256 7fddac63f04f83ecdf401ab7fbe54ce451ae9df8f65beb918c7ca702526290d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for timeout_iterator-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 725425bbbcc805dec00fd9a41fde98e1aa2c3f23fc3a8241b031a8e96c05ff01
MD5 2c4ceb10e0539766439ea882690cc851
BLAKE2b-256 4634d0f4fb9a7d20c694e4ec3561a344582c68c10472c78a142fac98d4017843

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