@@ -83,6 +83,17 @@ def _update_root_dir(self, proposal):
83
83
Only effective if cull_idle_timeout is not 0."""
84
84
)
85
85
86
+ buffer_offline_messages = Bool (True , config = True ,
87
+ help = """Whether messages from kernels whose frontends have disconnected should be buffered in-memory.
88
+
89
+ When True (default), messages are buffered and replayed on reconnect,
90
+ avoiding lost messages due to interrupted connectivity.
91
+
92
+ Disable if long-running kernels will produce too much output while
93
+ no frontends are connected.
94
+ """
95
+ )
96
+
86
97
_kernel_buffers = Any ()
87
98
@default ('_kernel_buffers' )
88
99
def _default_kernel_buffers (self ):
@@ -105,7 +116,7 @@ def cwd_for_path(self, path):
105
116
while not os .path .isdir (os_path ) and os_path != self .root_dir :
106
117
os_path = os .path .dirname (os_path )
107
118
return os_path
108
-
119
+
109
120
@gen .coroutine
110
121
def start_kernel (self , kernel_id = None , path = None , ** kwargs ):
111
122
"""Start a kernel for a session and return its kernel_id.
@@ -148,7 +159,7 @@ def start_kernel(self, kernel_id=None, path=None, **kwargs):
148
159
149
160
# py2-compat
150
161
raise gen .Return (kernel_id )
151
-
162
+
152
163
def start_buffering (self , kernel_id , session_key , channels ):
153
164
"""Start buffering messages for a kernel
154
165
@@ -163,6 +174,12 @@ def start_buffering(self, kernel_id, session_key, channels):
163
174
channels: dict({'channel': ZMQStream})
164
175
The zmq channels whose messages should be buffered.
165
176
"""
177
+
178
+ if not self .buffer_offline_messages :
179
+ for channel , stream in channels .items ():
180
+ stream .close ()
181
+ return
182
+
166
183
self .log .info ("Starting buffering for %s" , session_key )
167
184
self ._check_kernel_id (kernel_id )
168
185
# clear previous buffering state
@@ -182,7 +199,6 @@ def buffer_msg(channel, msg_parts):
182
199
for channel , stream in channels .items ():
183
200
stream .on_recv (partial (buffer_msg , channel ))
184
201
185
-
186
202
def get_buffer (self , kernel_id , session_key ):
187
203
"""Get the buffer for a given kernel
188
204
0 commit comments