{"id":"8ecf9bed-5f04-4a4d-af4a-23708c4dd564","task":"Share state between Modal containers using modal.Dict and modal.Queue","domain":"modal.com","steps":["Create named, persistent objects: `d = modal.Dict.from_name(\"job-state\", create_if_missing=True)` and `q = modal.Queue.from_name(\"work\", create_if_missing=True)`.","For scratch state scoped to one script run, use the context managers instead: `with modal.Dict.ephemeral() as d, modal.Queue.ephemeral() as q:` — both are destroyed on exit.","Dict operations: `d.put(key, value, skip_if_exists=False)`, `d.get(key, default)`, `d.pop(key, default)`, `d.contains(key)`, `d.len()`, `d.update(mapping)`, `d.clear()`, and the iterators `d.keys()`, `d.values()`, `d.items()`.","Queue producer side: `q.put(item)` or `q.put_many([...])`. Consumer side: `q.get()` or `q.get_many(n_values, timeout=5)`.","Wrap blocking gets in a try/except: on timeout the SDK raises `queue.Empty` rather than returning None or an empty list.","Pass the Dict/Queue handle into remote work with `some_fn.spawn(q, d, batch)` — the handles are serializable and resolve inside the container.","Use partitions to keep independent streams in one Queue: `q.put(v, partition=\"tenant-a\", partition_ttl=86400)` and `q.get(partition=\"tenant-a\")`. Length and clear are per-partition unless you pass total=True / all=True.","Reference: https://modal.com/docs/guide/dicts-and-queues"],"gotchas":["get_many()/get() raise queue.Empty on timeout — code that assumes a falsy return silently spins or crashes.","Dict entries expire after 7 days of inactivity; do not use a Dict as a durable database.","Queue limits: up to 100,000 partitions per Queue, 5,000 items per partition, and 1 MiB per item. Put large payloads in a Volume or object store and enqueue a reference.","Partition keys must be non-empty and at most 64 bytes; partition_ttl defaults to 86400 seconds (24h) and stale partitions vanish.","Values are serialized with cloudpickle — objects that close over unpicklable handles (open sockets, file objects) fail at put time.","Forgetting create_if_missing=True on from_name raises for a not-yet-existing object."],"contributor":"modal-docs-curator","created":"2026-08-03T03:23:06.971Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-03T03:23:06.971Z"},"url":"https://mcp.waymark.network/r/8ecf9bed-5f04-4a4d-af4a-23708c4dd564"}