@@ -86,6 +86,12 @@ def shutdown_gracefully(self, status=CLOSE_STATUS_NORMAL, reason=DEFAULT_CLOSE_R
8686 def shutdown_abruptly (self ):
8787 self ._shutdown_abruptly ()
8888
89+ def disconnect_clients_gracefully (self ):
90+ self ._disconnect_clients_gracefully ()
91+
92+ def disconnect_clients_abruptly (self ):
93+ self ._disconnect_clients_abruptly ()
94+
8995
9096class WebsocketServer (ThreadingMixIn , TCPServer , API ):
9197 """
@@ -196,12 +202,7 @@ def _shutdown_gracefully(self, status=CLOSE_STATUS_NORMAL, reason=DEFAULT_CLOSE_
196202 Send a CLOSE handshake to all connected clients before terminating server
197203 """
198204 self .keep_alive = False
199-
200- # Send CLOSE to clients
201- for client in self .clients :
202- client ["handler" ].send_close (CLOSE_STATUS_NORMAL , reason )
203-
204- self ._terminate_client_handlers ()
205+ self ._disconnect_clients_gracefully (status , reason )
205206 self .server_close ()
206207 self .shutdown ()
207208
@@ -210,10 +211,24 @@ def _shutdown_abruptly(self):
210211 Terminate server without sending a CLOSE handshake
211212 """
212213 self .keep_alive = False
213- self ._terminate_client_handlers ()
214+ self ._disconnect_clients_abruptly ()
214215 self .server_close ()
215216 self .shutdown ()
216217
218+ def _disconnect_clients_gracefully (self , status = CLOSE_STATUS_NORMAL , reason = DEFAULT_CLOSE_REASON ):
219+ """
220+ Terminate clients gracefully without shutting down the server
221+ """
222+ for client in self .clients :
223+ client ["handler" ].send_close (CLOSE_STATUS_NORMAL , reason )
224+ self ._terminate_client_handlers ()
225+
226+ def _disconnect_clients_abruptly (self ):
227+ """
228+ Terminate clients abruptly (no CLOSE handshake) without shutting down the server
229+ """
230+ self ._terminate_client_handlers ()
231+
217232
218233class WebSocketHandler (StreamRequestHandler ):
219234
0 commit comments