From ff87285f06026cc47ecb4c7c4e2ed87cd8c2d774 Mon Sep 17 00:00:00 2001 From: Thomas Baldwin Date: Mon, 25 Jan 2016 08:00:40 -0800 Subject: [PATCH] When configuring, ignore Zombie processes on OS X This patch was originally implemented by @jonnybaik, but got overwritten somewhere along the line. See Issue #431, Issue #432, and Issue #461 --- configure_nbextensions.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/configure_nbextensions.py b/configure_nbextensions.py index c89b868..831dee3 100644 --- a/configure_nbextensions.py +++ b/configure_nbextensions.py @@ -59,11 +59,25 @@ def update_config(config_file): for p in psutil.process_iter(): - if ("python" or "jupyter") in p.name(): - c = p.cmdline() - if len(c) == 2 and "jupyter-notebook" in c[1]: - print("Cannot configure while the Jupyter notebook server is running") - exit(1) + # p.name() can crash due to zombie processes on Mac OS X, so + # ignore exceptions due to zombie processes. + # (See https://code.google.com/p/psutil/issues/detail?id=428) + # Also, searching just the process name for string, "jupyter-notebook" may + # not be enough - may have to search the process command to see if + # jupyter-notebook is running. Checking the process command can cause an + # AccessDenied exception to be thrown for system owned processes, so skip + # those as well + try: + if ("python" or "jupyter") in p.name(): + c = p.cmdline() + if len(c) == 2 and "jupyter-notebook" in c[1]: + print("Cannot configure while the Jupyter notebook server is running") + exit(1) + # Ignore errors caused by zombie processes. Also ignore access + # denied exceptions that are thrown when checking the process + # comand of processes that do not belong to the user + except (psutil.ZombieProcess, psutil.AccessDenied): + pass if len(sys.argv) == 2 and sys.argv[1] == "debug": debug = True