@@ -37,9 +37,7 @@ def toggle_install(install, user=False, sys_prefix=False, overwrite=False,
37
37
symlink = False , prefix = None , nbextensions_dir = None ,
38
38
logger = None , skip_running_check = False ):
39
39
"""Install or remove all jupyter_contrib_nbextensions files & config."""
40
- if not skip_running_check and notebook_is_running ():
41
- raise NotebookRunningError (
42
- 'Cannot configure while the Jupyter notebook server is running' )
40
+ _err_on_running (skip_running_check = skip_running_check )
43
41
_check_conflicting_kwargs (user = user , sys_prefix = sys_prefix , prefix = prefix ,
44
42
nbextensions_dir = nbextensions_dir )
45
43
toggle_install_files (
@@ -55,9 +53,7 @@ def toggle_install_files(install, user=False, sys_prefix=False, logger=None,
55
53
overwrite = False , symlink = False , prefix = None ,
56
54
nbextensions_dir = None , skip_running_check = False ):
57
55
"""Install/remove jupyter_contrib_nbextensions files."""
58
- if not skip_running_check and notebook_is_running ():
59
- raise NotebookRunningError (
60
- 'Cannot configure while the Jupyter notebook server is running' )
56
+ _err_on_running (skip_running_check = skip_running_check )
61
57
kwargs = dict (user = user , sys_prefix = sys_prefix , prefix = prefix ,
62
58
nbextensions_dir = nbextensions_dir )
63
59
_check_conflicting_kwargs (** kwargs )
@@ -84,9 +80,7 @@ def toggle_install_files(install, user=False, sys_prefix=False, logger=None,
84
80
def toggle_install_config (install , user = False , sys_prefix = False ,
85
81
skip_running_check = False , logger = None ):
86
82
"""Install/remove contrib nbextensions to/from jupyter_nbconvert_config."""
87
- if not skip_running_check and notebook_is_running ():
88
- raise NotebookRunningError (
89
- 'Cannot configure while the Jupyter notebook server is running' )
83
+ _err_on_running (skip_running_check = skip_running_check )
90
84
_check_conflicting_kwargs (user = user , sys_prefix = sys_prefix )
91
85
config_dir = nbextensions ._get_config_dir (user = user , sys_prefix = sys_prefix )
92
86
if logger :
@@ -172,6 +166,29 @@ def uninstall(user=False, sys_prefix=False, prefix=None, nbextensions_dir=None,
172
166
# -----------------------------------------------------------------------------
173
167
174
168
169
+ def _err_on_running (skip_running_check = False , runtime_dir = None ):
170
+ if skip_running_check :
171
+ return
172
+ try :
173
+ srv = next (list_running_servers (runtime_dir = runtime_dir ))
174
+ except StopIteration :
175
+ return
176
+
177
+ raise NotebookRunningError ("""
178
+ Will not configure while a Jupyter notebook server appears to be running.
179
+ At least this server appears to be running:
180
+
181
+ {}
182
+
183
+ Note that the json file indicating that this server is running may
184
+ be stale, see
185
+
186
+ https://github.com/jupyter/notebook/issues/2829
187
+
188
+ for further details.
189
+ """ .format (srv ))
190
+
191
+
175
192
def _check_conflicting_kwargs (** kwargs ):
176
193
if sum (map (bool , kwargs .values ())) > 1 :
177
194
raise nbextensions .ArgumentConflict (
0 commit comments