Skip to content

Commit

Permalink
added --autoreload flag
Browse files Browse the repository at this point in the history
When passed, the webapp will watch for any changes to its Python source. On
change, all changed packages will be reimported and the webapp will restart.
Also works on Python source files in Jupyter server extensions. Implemented
using the built in `autoreload` parameter in the constructor of
`tornado.web.Application`.
  • Loading branch information
telamonian committed Jul 31, 2019
1 parent e498de6 commit a45c373
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def __init__(self, jupyter_app, kernel_manager, contents_manager,
default_url, settings_overrides, jinja_env_options)
handlers = self.init_handlers(settings)

if settings['autoreload']:
log.info('Autoreload enabled: the webapp will restart when any Python src file changes.')

super(NotebookWebApplication, self).__init__(handlers, **settings)

def init_settings(self, jupyter_app, kernel_manager, contents_manager,
Expand Down Expand Up @@ -542,6 +545,16 @@ def start(self):
_("Allow the notebook to be run from root user.")
)

flags['autoreload'] = (
{'NotebookApp': {'autoreload': True}},
"""Autoreload the webapp
Enable reloading of the tornado webapp and all imported Python packages
when any changes are made to any Python src files in Notebook or
extensions.
"""
)

# Add notebook manager flags
flags.update(boolean_flag('script', 'FileContentsManager.save_script',
'DEPRECATED, IGNORED',
Expand Down Expand Up @@ -648,6 +661,10 @@ def _default_log_format(self):
help=_("Whether to allow the user to run the notebook as root.")
)

autoreload = Bool(False, config=True,
help= ("Reload the webapp when changes are made to any Python src files.")
)

default_url = Unicode('/tree', config=True,
help=_("The default URL to redirect to from `/`")
)
Expand Down Expand Up @@ -1386,6 +1403,7 @@ def init_webapp(self):
if self.allow_origin_pat:
self.tornado_settings['allow_origin_pat'] = re.compile(self.allow_origin_pat)
self.tornado_settings['allow_credentials'] = self.allow_credentials
self.tornado_settings['autoreload'] = self.autoreload
self.tornado_settings['cookie_options'] = self.cookie_options
self.tornado_settings['get_secure_cookie_kwargs'] = self.get_secure_cookie_kwargs
self.tornado_settings['token'] = self.token
Expand Down

0 comments on commit a45c373

Please sign in to comment.