Skip to main content

Wrapper on iterable for automatic caching, resuming, retrying, and multiprocessing

Project description

Wrapper on an iterable to support interruption & auto resume, retrying and multiprocessing.

The code is tested on Linux.

APIs

Please refer to the signature of function.iterate_wrapper or generator.IterateWrapper for usage.

Examples

iterate_wrapper

from typing import IO
from time import sleep

from iterwrap import iterate_wrapper

def square(f_io: IO, item: int, fn: Callable[[float], float]):
    result = fn(item)
    f_io.write(f"{result}\n")

data = list(range(10))
num_workers = 3
iterate_wrapper(
    square,
    data,
    output="output.txt",
    num_workers=num_workers,
    fn=lambda x: x * x,
)

with open("output.txt") as f:
    print(f.read()) # [0, 1, 4, 9, ..., 81]

IterateWrapper

Just the same as tqdm.tqdm.

from iterwrap import IterateWrapper

data = [1, 2, 3]
results = []
for i in IterateWrapper(data):
    results.append(i * i)
print(results) # [1, 4, 9]

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

iterwrap-0.4.3.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iterwrap-0.4.3-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file iterwrap-0.4.3.tar.gz.

File metadata

  • Download URL: iterwrap-0.4.3.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for iterwrap-0.4.3.tar.gz
Algorithm Hash digest
SHA256 c7b7901a12baafdf3225ca167991f37ce3ade20fdb8a9398e089e807ea1ea77b
MD5 93689407039c82a23e35115dd7db5cb9
BLAKE2b-256 5a0d4ac303a77c8e45c855559c2ddccc09337ba0f2b558207397b841f7697776

See more details on using hashes here.

File details

Details for the file iterwrap-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: iterwrap-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 33.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for iterwrap-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 98876c2681fedb7efc65400edb72f015bd40505cb9627f0fdc9169d5eb2e9f3f
MD5 7545ab6036788f1fb189b21c91214a5e
BLAKE2b-256 c7ab5167fb54e0acfa0ab4f8d79afd91f1907f3e34f3fa0e38242b7be18f1a18

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