From 52462c416a84f9e209b34efa03ac7ae124b4ca58 2011-05-07 19:54:43 From: epatters Date: 2011-05-07 19:54:43 Subject: [PATCH] Handle Unix ESRCH errors gracefully in kill_kernel. --- diff --git a/IPython/zmq/kernelmanager.py b/IPython/zmq/kernelmanager.py index a099f95..4b30621 100644 --- a/IPython/zmq/kernelmanager.py +++ b/IPython/zmq/kernelmanager.py @@ -835,8 +835,15 @@ class KernelManager(HasTraits): except OSError, e: # In Windows, we will get an Access Denied error if the process # has already terminated. Ignore it. - if not (sys.platform == 'win32' and e.winerror == 5): - raise + if sys.platform == 'win32': + if e.winerror != 5: + raise + # On Unix, we may get an ESRCH error if the process has already + # terminated. Ignore it. + else: + from errno import ESRCH + if e.errno != ESRCH: + raise self.kernel = None else: raise RuntimeError("Cannot kill kernel. No kernel is running!")