Skip to main content

Efficient Ray-powered map/imap with backpressure, checkpointing, timeouts, and async

Project description

ray-map

Efficient Ray-powered imap/map with backpressure, checkpointing, per-item timeouts, safe exceptions, and async variants.

Features

  • ⚡ Parallel map/imap on [Ray] with back-pressure and batching
  • 💾 Checkpointing + replay of already computed points
  • ⏱️ Per-item timeouts (worker-side, via threads)
  • 🧯 Safe exceptions: return Exception objects instead of failing the whole run
  • 🔁 Ordered or as-ready modes, (arg, res) or plain res
  • 🧰 Async API: imap_async, map_async
  • 🧩 Works with single file module ray_map.py, src-layout, no extra boilerplate

Install

pip install ray-map

Quickstart

from ray_map import RayMap

def foo(x):
    if x == 3:
        raise ValueError("oops")
    return x * x

rmap = RayMap(foo, batch_size=8, max_pending=-1, checkpoint_path="res.pkl")

# stream (ordered), exceptions raise by default
for y in rmap.imap(range(10)):
    print(y)

# stream (as-ready), safe exceptions, return (arg, res_or_exc)
for arg, res in rmap.imap(range(10), keep_order=False, safe_exceptions=True, ret_args=True, timeout=2.0):
    print(arg, "->", res)

# list
lst = rmap.map(range(1000), timeout=2.0, safe_exceptions=True)

API essentials

RayMap.imap(iterable, *, timeout=None, safe_exceptions=False, keep_order=True, ret_args=False) -> iterator
RayMap.map(iterable,  *, timeout=None, safe_exceptions=False, keep_order=True, ret_args=False) -> list

# Async variants
RayMap.imap_async(...): async iterator
RayMap.map_async(...): list
  • timeout: per-item timeout (seconds) on worker via ThreadPoolExecutor
  • safe_exceptions=True: return exception objects (no crash)
  • keep_order=True: preserve input order (1:1); False → yield as-ready
  • ret_args=True: yield (arg, res_or_exc) instead of just res_or_exc

Checkpointing

  • Stores (key, arg, result_or_exc) to checkpoint_path.
  • On restart, previously computed results are yielded first; then Ray resumes the rest.
  • (Optional) You can add a flag to skip storing exceptions in a future version

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

ray_map-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

ray_map-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file ray_map-0.1.0.tar.gz.

File metadata

  • Download URL: ray_map-0.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ray_map-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eac94a1248fb667db922330799c3a75595e1531bd493a266e9a2a0b8a87c18fb
MD5 f7ce508ba57ea8059faae2b9d1d066f9
BLAKE2b-256 0c46a2870075248f9e4e28f0c6c13a1775ec3a0f055fc87f29508df69e572707

See more details on using hashes here.

File details

Details for the file ray_map-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ray_map-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ray_map-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3200c62590c440ebac5d51a27ad9562b66ecd41a9c0b30fefe895b1a3e4cb4f
MD5 fbd9b8408bb52a746e19083474a15be3
BLAKE2b-256 28fa3cadcdfeef15f4d8b3c85eec2f23b73f1b2fb82f1114c62d65fc0c9809f4

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