Before you run#
Use an installed, authenticated Yak CLI with access to the invite-only preview. Read Parallel Execution for the full setup and current behavior.
Python example
Map a task over a sequence with bounded concurrency and ordered results.
Use an installed, authenticated Yak CLI with access to the invite-only preview. Read Parallel Execution for the full setup and current behavior.
import asyncio
import yak
app = yak.App(name="parallel-task-map", image="python:3.11")
@app.task()
def square(value: int) -> int:
return value * value
@app.entrypoint()
async def main() -> None:
results = square.map.aio(range(1, 6), max_in_flight=3)
try:
async for result in results:
print(result)
finally:
await results.aclose()
if __name__ == "__main__":
asyncio.run(main())
Save the source as parallel_task_map.py, then run:
$ yak run parallel_task_map.py