@@ -240,6 +240,8 @@ def __init__(
240
240
authorizer = None ,
241
241
identity_provider = None ,
242
242
kernel_websocket_connection_class = None ,
243
+ websocket_ping_interval = None ,
244
+ websocket_ping_timeout = None ,
243
245
):
244
246
"""Initialize a server web application."""
245
247
if identity_provider is None :
@@ -277,6 +279,8 @@ def __init__(
277
279
authorizer = authorizer ,
278
280
identity_provider = identity_provider ,
279
281
kernel_websocket_connection_class = kernel_websocket_connection_class ,
282
+ websocket_ping_interval = websocket_ping_interval ,
283
+ websocket_ping_timeout = websocket_ping_timeout ,
280
284
)
281
285
handlers = self .init_handlers (default_services , settings )
282
286
@@ -301,6 +305,8 @@ def init_settings(
301
305
authorizer = None ,
302
306
identity_provider = None ,
303
307
kernel_websocket_connection_class = None ,
308
+ websocket_ping_interval = None ,
309
+ websocket_ping_timeout = None ,
304
310
):
305
311
"""Initialize settings for the web application."""
306
312
_template_path = settings_overrides .get (
@@ -383,6 +389,8 @@ def init_settings(
383
389
"identity_provider" : identity_provider ,
384
390
"event_logger" : event_logger ,
385
391
"kernel_websocket_connection_class" : kernel_websocket_connection_class ,
392
+ "websocket_ping_interval" : websocket_ping_interval ,
393
+ "websocket_ping_timeout" : websocket_ping_timeout ,
386
394
# handlers
387
395
"extra_services" : extra_services ,
388
396
# Jupyter stuff
@@ -1515,6 +1523,32 @@ def _default_kernel_websocket_connection_class(
1515
1523
return "jupyter_server.gateway.connections.GatewayWebSocketConnection"
1516
1524
return ZMQChannelsWebsocketConnection
1517
1525
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
+
1518
1552
config_manager_class = Type (
1519
1553
default_value = ConfigManager ,
1520
1554
config = True ,
@@ -2101,6 +2135,8 @@ def init_webapp(self) -> None:
2101
2135
authorizer = self .authorizer ,
2102
2136
identity_provider = self .identity_provider ,
2103
2137
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 ,
2104
2140
)
2105
2141
if self .certfile :
2106
2142
self .ssl_options ["certfile" ] = self .certfile
0 commit comments