10
10
11
11
import jupyter_highlight_selected_word
12
12
import latex_envs
13
- import psutil
14
13
from jupyter_contrib_core .notebook_compat import nbextensions
15
14
from jupyter_nbextensions_configurator .application import \
16
15
EnableJupyterNbextensionsConfiguratorApp
16
+ from notebook .notebookapp import list_running_servers
17
17
from traitlets .config import Config
18
18
from traitlets .config .manager import BaseJSONConfigManager
19
19
@@ -24,28 +24,11 @@ class NotebookRunningError(Exception):
24
24
pass
25
25
26
26
27
- def notebook_is_running ():
27
+ def notebook_is_running (runtime_dir = None ):
28
28
"""Return true if a notebook process appears to be running."""
29
- for p in psutil .process_iter ():
30
- # p.name() can throw exceptions due to zombie processes on Mac OS X, so
31
- # ignore psutil.ZombieProcess
32
- # (See https://code.google.com/p/psutil/issues/detail?id=428)
33
-
34
- # It isn't enough to search just the process name, we have to
35
- # search the process command to see if jupyter-notebook is running.
36
-
37
- # Checking the process command can cause an AccessDenied exception to
38
- # be thrown for system owned processes, ignore those as well
39
- try :
40
- # use lower, since python may be Python, e.g. on OSX
41
- if ('python' or 'jupyter' ) in p .name ().lower ():
42
- for arg in p .cmdline ():
43
- # the missing k is deliberate!
44
- # The usual string 'jupyter-notebook' can get truncated.
45
- if 'jupyter-noteboo' in arg :
46
- return True
47
- except (psutil .ZombieProcess , psutil .AccessDenied ):
48
- pass
29
+ try :
30
+ return bool (next (list_running_servers (runtime_dir = runtime_dir )))
31
+ except StopIteration :
49
32
return False
50
33
51
34
0 commit comments