Skip to content

A programming framework for agentic AI

Update Distributed Agent Runtime Cross-platform Sample (#5164)

linznin33d9bd6d1df6
diff --git a/python/samples/core_grpc_worker_runtime/run_host.py b/python/samples/core_grpc_worker_runtime/run_host.py
index 3f899987c..5a1170ec0 100644
--- a/python/samples/core_grpc_worker_runtime/run_host.py
+++ b/python/samples/core_grpc_worker_runtime/run_host.py
@@ -1,4 +1,5 @@
import asyncio
+import os
from autogen_ext.runtimes.grpc import GrpcWorkerAgentRuntimeHost
@@ -6,7 +7,18 @@ from autogen_ext.runtimes.grpc import GrpcWorkerAgentRuntimeHost
async def main() -> None:
service = GrpcWorkerAgentRuntimeHost(address="localhost:50051")
service.start()
- await service.stop_when_signal()
+
+ try:
+ # Wait for the service to stop
+ if os.system() == "Windows":
+ # On Windows, the signal is not available, so we wait for a new event
+ await asyncio.Event().wait()
+ else:
+ await service.stop_when_signal()
+ except KeyboardInterrupt:
+ print("Stopping service...")
+ finally:
+ await service.stop()
if __name__ == "__main__":