@@ -240,6 +240,8 @@ def __init__(
240240 authorizer = None ,
241241 identity_provider = None ,
242242 kernel_websocket_connection_class = None ,
243+ websocket_ping_interval = None ,
244+ websocket_ping_timeout = None ,
243245 ):
244246 """Initialize a server web application."""
245247 if identity_provider is None :
@@ -277,6 +279,8 @@ def __init__(
277279 authorizer = authorizer ,
278280 identity_provider = identity_provider ,
279281 kernel_websocket_connection_class = kernel_websocket_connection_class ,
282+ websocket_ping_interval = websocket_ping_interval ,
283+ websocket_ping_timeout = websocket_ping_timeout ,
280284 )
281285 handlers = self .init_handlers (default_services , settings )
282286
@@ -301,6 +305,8 @@ def init_settings(
301305 authorizer = None ,
302306 identity_provider = None ,
303307 kernel_websocket_connection_class = None ,
308+ websocket_ping_interval = None ,
309+ websocket_ping_timeout = None ,
304310 ):
305311 """Initialize settings for the web application."""
306312 _template_path = settings_overrides .get (
@@ -383,6 +389,8 @@ def init_settings(
383389 "identity_provider" : identity_provider ,
384390 "event_logger" : event_logger ,
385391 "kernel_websocket_connection_class" : kernel_websocket_connection_class ,
392+ "websocket_ping_interval" : websocket_ping_interval ,
393+ "websocket_ping_timeout" : websocket_ping_timeout ,
386394 # handlers
387395 "extra_services" : extra_services ,
388396 # Jupyter stuff
@@ -1515,6 +1523,32 @@ def _default_kernel_websocket_connection_class(
15151523 return "jupyter_server.gateway.connections.GatewayWebSocketConnection"
15161524 return ZMQChannelsWebsocketConnection
15171525
1526+ websocket_ping_interval = Integer (
1527+ config = True ,
1528+ help = """
1529+ Configure the websocket ping interval in seconds.
1530+
1531+ Websockets are long-lived connections that are used by some Jupyter
1532+ Server extensions.
1533+
1534+ Periodic pings help to detect disconnected clients and keep the
1535+ connection active. If this is set to None, then no pings will be
1536+ performed.
1537+
1538+ When a ping is sent, the client has ``websocket_ping_timeout``
1539+ seconds to respond. If no response is received within this period,
1540+ the connection will be closed from the server side.
1541+ """ ,
1542+ )
1543+ websocket_ping_timeout = Integer (
1544+ config = True ,
1545+ help = """
1546+ Configure the websocket ping timeout in seconds.
1547+
1548+ See ``websocket_ping_interval`` for details.
1549+ """ ,
1550+ )
1551+
15181552 config_manager_class = Type (
15191553 default_value = ConfigManager ,
15201554 config = True ,
@@ -2101,6 +2135,8 @@ def init_webapp(self) -> None:
21012135 authorizer = self .authorizer ,
21022136 identity_provider = self .identity_provider ,
21032137 kernel_websocket_connection_class = self .kernel_websocket_connection_class ,
2138+ websocket_ping_interval = self .websocket_ping_interval ,
2139+ websocket_ping_timeout = self .websocket_ping_timeout ,
21042140 )
21052141 if self .certfile :
21062142 self .ssl_options ["certfile" ] = self .certfile
0 commit comments