Skip to content

Commit 84b7b85

Browse files
committed
Apply review comments, revert interval validation, bump terminado to 0.8.3
1 parent 2064957 commit 84b7b85

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

notebook/notebookapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ def init_terminals(self):
17431743

17441744
try:
17451745
from .terminal import initialize
1746-
initialize(self.web_app, self.notebook_dir, self.connection_url, self.terminado_settings, self)
1746+
initialize(parent=self)
17471747
self.web_app.settings['terminals_available'] = True
17481748
except ImportError as e:
17491749
self.log.warning(_("Terminals not available (error was %s)"), e)

notebook/terminal/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@
1414
from . import api_handlers
1515

1616

17-
def initialize(webapp, notebook_dir, connection_url, settings, parent):
17+
def initialize(parent):
1818
if os.name == 'nt':
1919
default_shell = 'powershell.exe'
2020
else:
2121
default_shell = which('sh')
22-
shell = settings.get('shell_command',
22+
shell = parent.terminado_settings.get('shell_command',
2323
[os.environ.get('SHELL') or default_shell]
2424
)
2525
# Enable login mode - to automatically source the /etc/profile script
2626
if os.name != 'nt':
2727
shell.append('-l')
28-
terminal_manager = webapp.settings['terminal_manager'] = TerminalManager(
28+
terminal_manager = parent.web_app.settings['terminal_manager'] = TerminalManager(
2929
shell_command=shell,
30-
extra_env={'JUPYTER_SERVER_ROOT': notebook_dir,
31-
'JUPYTER_SERVER_URL': connection_url,
30+
extra_env={'JUPYTER_SERVER_ROOT': parent.notebook_dir,
31+
'JUPYTER_SERVER_URL': parent.connection_url,
3232
},
3333
parent=parent,
3434
)
35-
terminal_manager.log = app_log
36-
base_url = webapp.settings['base_url']
35+
terminal_manager.log = parent.log
36+
base_url = parent.web_app.settings['base_url']
3737
handlers = [
3838
(ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler),
3939
(ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket,
4040
{'term_manager': terminal_manager}),
4141
(ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler),
4242
(ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler),
4343
]
44-
webapp.add_handlers(".*$", handlers)
44+
parent.web_app.add_handlers(".*$", handlers)

notebook/terminal/terminalmanager.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
from tornado import web
1515
from tornado.ioloop import IOLoop, PeriodicCallback
1616
from traitlets import Integer, validate
17-
from traitlets.config import Configurable
17+
from traitlets.config import LoggingConfigurable
1818
from ..prometheus.metrics import TERMINAL_CURRENTLY_RUNNING_TOTAL
1919

2020

21-
class TerminalManager(Configurable, NamedTermManager):
21+
class TerminalManager(LoggingConfigurable, NamedTermManager):
2222
""" """
2323

2424
_culler_callback = None
@@ -35,15 +35,6 @@ class TerminalManager(Configurable, NamedTermManager):
3535
help="""The interval (in seconds) on which to check for terminals exceeding the inactive timeout value."""
3636
)
3737

38-
@validate('cull_interval')
39-
def _cull_interval_validate(self, proposal):
40-
value = proposal['value']
41-
if value <= 0:
42-
warnings.warn("Invalid value for 'cull_interval' detected ({}) - using default value ({}).".
43-
format(value, self.cull_interval_default))
44-
value = self.cull_interval_default
45-
return value
46-
4738
# -------------------------------------------------------------------------
4839
# Methods for managing terminals
4940
# -------------------------------------------------------------------------
@@ -118,6 +109,10 @@ def _initialize_culler(self):
118109
if not self._initialized_culler and self.cull_inactive_timeout > 0:
119110
if self._culler_callback is None:
120111
loop = IOLoop.current()
112+
if self.cull_interval <= 0: # handle case where user set invalid value
113+
self.log.warning("Invalid value for 'cull_interval' detected (%s) - using default value (%s).",
114+
self.cull_interval, self.cull_interval_default)
115+
self.cull_interval = self.cull_interval_default
121116
self._culler_callback = PeriodicCallback(
122117
self._cull_terminals, 1000 * self.cull_interval)
123118
self.log.info("Culling terminals with inactivity > %s seconds at %s second intervals ...",

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
'nbconvert',
111111
'ipykernel', # bless IPython kernel for now
112112
'Send2Trash',
113-
'terminado>=0.8.1',
113+
'terminado>=0.8.3',
114114
'prometheus_client'
115115
],
116116
extras_require = {

0 commit comments

Comments
 (0)