Iterator with timeout
Project description
python-timeout-iterator
timeout-iterator
provides a timeout in iteration.
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
Release history Release notifications | RSS feed
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 details)
Built Distribution
File details
Details for the file timeout-iterator-0.1.1.tar.gz
.
File metadata
- Download URL: timeout-iterator-0.1.1.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66748eb5bfcbe665c07c6e18604da589055432b07e975663e0b6bda7c669eb13 |
|
MD5 | 66d8e1d15ab14d93e5ddf2454916a0c3 |
|
BLAKE2b-256 | cef2bd690a81627e0ffd1456a01b329bf468e2387a62ff841fc3b4c92bf2d57f |
File details
Details for the file timeout_iterator-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: timeout_iterator-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a84a7cfc9271a396f8c9c74b8da8a7b7dab246af23c879d5484391a05a1acf0b |
|
MD5 | f355821d6327dbe5b67e6299e88ad214 |
|
BLAKE2b-256 | e350eda0322477196c8b0d54ef74e7365ea70bc8d2283bc5aa4e2072ae1096ac |