Available at PyPi
Provides a wrapper class TimeoutIterator to add timeout feature to normal iterators
Installation:
pip install iterators
See help of TimeoutIterator for all the features. Check tests for examples on how to use TimeoutIterator. See example tests below for basic usage
Example:
-
TimeoutIterator works like normal iterator:
from iterators import TimeoutIterator def iter_simple(): yield 1 yield 2 def test_normal_iteration(self): i = iter_simple() it = TimeoutIterator(i) self.assertEqual(next(it), 1) self.assertEqual(next(it), 2) self.assertRaises(StopIteration, next, it) self.assertRaises(StopIteration, next, it) -
When timeout is needed, use like this
def iter_with_sleep(): yield 1 time.sleep(0.6) yield 2 time.sleep(0.4) yield 3 def test_fixed_timeout(self): i = iter_with_sleep() it = TimeoutIterator(i, timeout=0.5) self.assertEqual(next(it), 1) self.assertEqual(next(it), it.get_sentinel()) self.assertEqual(next(it), 2) self.assertEqual(next(it), 3) self.assertRaises(StopIteration, next, it) -
Dynamic timeout adjustment
def iter_with_sleep(): yield 1 time.sleep(0.6) yield 2 time.sleep(0.4) yield 3 def test_timeout_update(self): i = iter_with_sleep() it = TimeoutIterator(i, timeout=0.5) self.assertEqual(next(it), 1) self.assertEqual(next(it), it.get_sentinel()) it.set_timeout(0.3) self.assertEqual(next(it), 2) self.assertEqual(next(it), it.get_sentinel()) self.assertEqual(next(it), 3) self.assertRaises(StopIteration, next, it)
Run unit tests locally:
python -m unittest discover tests
Metadata
Release files for iterators 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iterators-0.2.0.tar.gz | 4.3 kB | Without provenance | Details for iterators-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iterators-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for iterators-0.2.0-py3-none-any.whl |
Total release size: 9.3 kB
Release files / iterators-0.2.0.tar.gz
| Download URL | iterators-0.2.0.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9927a1ea1ef081830fd1512f3916857c36bd4b37272819a6cd29d0f44431b97
|
|
BLAKE2b-256 checksum How to use checksums |
02c4135b5bdb9f14f728fe1274361b336f77c5f1606af9a5622a765fe75f5fa0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / iterators-0.2.0-py3-none-any.whl
| Download URL | iterators-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d7ff03f576c9de0e01bac66209556c066d6b1fc45583a99cfc9f4645be7900e
|
|
BLAKE2b-256 checksum How to use checksums |
bda19c29772ac9f3bdf9837c92ba5c1fc93f75da14c2e0c3fc41e10485f68feb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for iterators 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.