Fan out with .map()
from klio_compute import function
@function(cpu=1, memory="1Gi")
def square(x: int) -> int:
return x * x
if __name__ == "__main__":
for result in square.map([1, 2, 3, 4]):
print(result).map() sends every input to its own container and gives back the results. With @function, results arrive as calls finish; a failed input is reported and yields None. Each container is billed for the seconds it runs.
With the Modal-compatible API
import klio_compute.compat as modal
app = modal.App("thumbnails")
@app.function()
def thumbnail(path: str) -> str:
...
@app.local_entrypoint()
def main():
print(list(thumbnail.map(["a.png", "b.png", "c.png"])))Here .map() returns results in input order, as Modal does, and keeps a bounded number of calls in flight however long the input is.