Skip to content

Commit 96dd8c4

Browse files
committed
Wrong use of timeout. Now proper grace period time
1 parent 773fabe commit 96dd8c4

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

scripts_of_tribute/server.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import time
21
from typing import Tuple
32
import grpc
43
from concurrent import futures
@@ -47,13 +46,8 @@ def CloseServer(self, request, context):
4746
print(f"Received CloseServer request from {self.ai.bot_name}. Shutting down server...")
4847
context.set_code(grpc.StatusCode.OK)
4948
context.set_details(f"Bot {self.ai.bot_name}'s connection closed.")
50-
def delayed_shutdown():
51-
time.sleep(0.1)
52-
self.server_instance.bot_disconnected()
53-
print(f"Bot {self.ai.bot_name}'s connection closed.")
54-
55-
import threading
56-
threading.Thread(target=delayed_shutdown, daemon=True).start()
49+
self.server_instance.bot_disconnected()
50+
print(f"Bot {self.ai.bot_name}'s connection closed.")
5751

5852
return main_pb2.Empty()
5953

@@ -74,7 +68,7 @@ def bot_disconnected(self):
7468

7569
def shutdown_server(self):
7670
if self.server:
77-
self.server.stop(0)
71+
self.server.stop(2)
7872
else:
7973
print("Server is already stopped.")
8074

@@ -108,12 +102,6 @@ def run_grpc_server(
108102
server2.server.start()
109103

110104
if bot1 is not None:
111-
try:
112-
server1.server.wait_for_termination(timeout=2)
113-
except grpc.FutureTimeoutError:
114-
print("Server didn't terminate cleanly in time.")
105+
server1.server.wait_for_termination()
115106
if bot2 is not None:
116-
try:
117-
server2.server.wait_for_termination(timeout=2)
118-
except grpc.FutureTimeoutError:
119-
print("Server didn't terminate cleanly in time.")
107+
server2.server.wait_for_termination()

0 commit comments

Comments
 (0)