Skip to content

Commit b5d33cb

Browse files
committed
fix: improve service shutdown handling in for cross-platform compatibility (#5124)
1 parent 226b37d commit b5d33cb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

python/samples/core_grpc_worker_runtime/run_host.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import asyncio
2+
import os
23

34
from autogen_ext.runtimes.grpc import GrpcWorkerAgentRuntimeHost
45

56

67
async def main() -> None:
78
service = GrpcWorkerAgentRuntimeHost(address="localhost:50051")
89
service.start()
9-
await service.stop_when_signal()
10+
11+
try:
12+
# Wait for the service to stop
13+
if os.system() == "Windows":
14+
# On Windows, the signal is not available, so we wait for a new event
15+
await asyncio.Event().wait()
16+
else:
17+
await service.stop_when_signal()
18+
except KeyboardInterrupt:
19+
print("Stopping service...")
20+
finally:
21+
await service.stop()
1022

1123

1224
if __name__ == "__main__":

0 commit comments

Comments
 (0)