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.6.tar.gz (27.5 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.6-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iterwrap-0.4.6.tar.gz
  • Upload date:
  • Size: 27.5 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.6.tar.gz
Algorithm Hash digest
SHA256 b72f2dc29eea29d16535879c71aebcb6752935d1c367ca4a52c9f033ef1f1411
MD5 dccf3d1ab76aa74be00837769cac5eb7
BLAKE2b-256 d9d74fb48d90b0e391a5c918e18fc8633426fc56eeaea42efa53c287693075a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iterwrap-0.4.6-py3-none-any.whl
  • Upload date:
  • Size: 28.5 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 91909984354ab37533ab65ba92629a0de80056097cc2365b0f69dfefe603808d
MD5 2b9f7b607f94a3a24812ea50eed5cb2d
BLAKE2b-256 97109536a8918c2e852a730dc110fa15545f2111b990f2321a725de7e5f46132

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