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.3.2.tar.gz (21.8 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.3.2-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iterwrap-0.3.2.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.13

File hashes

Hashes for iterwrap-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c70b810415c5bc1ea7d6256f780c10f656660e22b3f1ecb705f5b5de4f55b248
MD5 57c24ddcb69e4a778642b956a8f0a357
BLAKE2b-256 629e7cbf6519085db3e1cc42ebef3ef15c1a19a2c39cad271365696837bd3743

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iterwrap-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.13

File hashes

Hashes for iterwrap-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7be48da16a7daa446c386a043d7b2b263c5434526cb5227d10b2f18bb107898c
MD5 879bac6cf192ce9e45b870de5ec03fb0
BLAKE2b-256 e100ad97e9923e3a6fa3881a981a80a67bab790b5c38d0c9bac752eb26a2d66d

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