Skip to content

Commit

Permalink
fix: improve service shutdown handling in for cross-platform compatib…
Browse files Browse the repository at this point in the history
…ility (microsoft#5124)
  • Loading branch information
linznin committed Jan 23, 2025
1 parent 226b37d commit b5d33cb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion python/samples/core_grpc_worker_runtime/run_host.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import asyncio
import os

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__":
Expand Down

0 comments on commit b5d33cb

Please sign in to comment.