An interuptable iterator for Python
Project description
stop_iter
stop_iter
takes an iterable and returns a new iterable that can be safely stopped using SIGINT
. This is useful when you have a long-running computation, such as machine learning training loops, that you want to be able to stop without losing all of the work that has been done so far.
Installation
pip install stop_iter
Usage
The following code will print the integers until you press Ctrl+C
and then print "infinity".
from stop_iter import stop_iter
def integers():
count = 0
while True:
yield (count := count + 1)
for n in stop_iter(integers()):
print(n)
print("\ninfinity")
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
stop_iter-0.2.4.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file stop_iter-0.2.4.tar.gz
.
File metadata
- Download URL: stop_iter-0.2.4.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.4 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa4272fef75b4d11ae9e9466b122e17f24cddfeca166703c786295e777d4f624 |
|
MD5 | dfc8962103b80a6ad620c22bf1016da1 |
|
BLAKE2b-256 | 3314c022407155f6b7d45b061698e757c5b3662783d00c7607f76604c32020d7 |
File details
Details for the file stop_iter-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: stop_iter-0.2.4-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.4 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0276a7b68653d890064870a3ab0657ed68721f46af9da1701786110e8571fb0 |
|
MD5 | d7e6fb542eaa20e39d2082d97dd5b6a6 |
|
BLAKE2b-256 | f81333eef7ab26b5efcf8b8b1a30ce467ed8efa2a0d8addc888bd1178ee8e62e |