Spaces:
Running
Running
Download examples/dispatch.py from pgg-engineering/guardshift: direct link, hf CLI and curl.
- Browser
- Download file 726 Bytes
-
https://huggingface.co/spaces/pgg-engineering/guardshift/resolve/main/examples/dispatch.py
- Command line
-
hf download hf://spaces/pgg-engineering/guardshift/examples/dispatch.py
-
curl -L -o dispatch.py https://huggingface.co/spaces/pgg-engineering/guardshift/resolve/main/examples/dispatch.py
726 Bytes
| """Batch two telemetry writes before dispatching an agent.""" | |
| import asyncio | |
| from guardshift import Index | |
| async def worker(inbox): | |
| event = await inbox.get() | |
| print("batch worker received", event) | |
| async def main(): | |
| # Start the batch worker when queue depth >= 100 and GPU usage <= 70%. | |
| guards = [[(0, 100, 2**63 - 1), (1, 0, 70)]] | |
| index = Index([95, 60], guards) | |
| inbox = asyncio.Queue() | |
| task = asyncio.create_task(worker(inbox)) | |
| for patch in [[(0, 101), (1, 85)], [(1, 65)]]: | |
| for guard_id, active in index.apply(patch): | |
| if active: | |
| await inbox.put({"guard_id": guard_id, "patch": patch}) | |
| await task | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |