Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow disabling offline message buffering #2916

Merged
merged 1 commit into from
Oct 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions notebook/services/kernels/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def _update_root_dir(self, proposal):
Only effective if cull_idle_timeout is not 0."""
)

buffer_offline_messages = Bool(True, config=True,
help="""Whether messages from kernels whose frontends have disconnected should be buffered in-memory.

When True (default), messages are buffered and replayed on reconnect,
avoiding lost messages due to interrupted connectivity.

Disable if long-running kernels will produce too much output while
no frontends are connected.
"""
)

_kernel_buffers = Any()
@default('_kernel_buffers')
def _default_kernel_buffers(self):
Expand All @@ -105,7 +116,7 @@ def cwd_for_path(self, path):
while not os.path.isdir(os_path) and os_path != self.root_dir:
os_path = os.path.dirname(os_path)
return os_path

@gen.coroutine
def start_kernel(self, kernel_id=None, path=None, **kwargs):
"""Start a kernel for a session and return its kernel_id.
Expand Down Expand Up @@ -148,7 +159,7 @@ def start_kernel(self, kernel_id=None, path=None, **kwargs):

# py2-compat
raise gen.Return(kernel_id)

def start_buffering(self, kernel_id, session_key, channels):
"""Start buffering messages for a kernel

Expand All @@ -163,6 +174,12 @@ def start_buffering(self, kernel_id, session_key, channels):
channels: dict({'channel': ZMQStream})
The zmq channels whose messages should be buffered.
"""

if not self.buffer_offline_messages:
for channel, stream in channels.items():
stream.close()
return

self.log.info("Starting buffering for %s", session_key)
self._check_kernel_id(kernel_id)
# clear previous buffering state
Expand All @@ -182,7 +199,6 @@ def buffer_msg(channel, msg_parts):
for channel, stream in channels.items():
stream.on_recv(partial(buffer_msg, channel))


def get_buffer(self, kernel_id, session_key):
"""Get the buffer for a given kernel

Expand Down