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.4.tar.gz (28.0 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.4-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iterwrap-0.4.4.tar.gz
  • Upload date:
  • Size: 28.0 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.4.tar.gz
Algorithm Hash digest
SHA256 8ceb7cec6f3991a25ff9024f7703bca8ab782c6bdef8498cba649f9e4349beb5
MD5 4cec4b899ffcc89d838139b9d8a98b3d
BLAKE2b-256 7ed7930e694a752cd71375c8f6794e125a293d0428f23318424290eb8a070e9f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iterwrap-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 29.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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d7b69ee13a38196ab394950117450196ae183ccea3c6a8a08d772b3950700985
MD5 adbf9d96b4da53c6fa708f0026585cea
BLAKE2b-256 4cb9492b0a5f8c0c2671375ce07316c93c704e12ee0c7b9a7f157fb852b63add

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