From c927714638d15e4f049b20a1ed20896f90a53535 2012-06-14 01:08:08 From: Takafumi Arakaki Date: 2012-06-14 01:08:08 Subject: [PATCH] Avoid error while killing subprocess in %%script --- diff --git a/IPython/core/magics/script.py b/IPython/core/magics/script.py index 28d7c06..4904e54 100644 --- a/IPython/core/magics/script.py +++ b/IPython/core/magics/script.py @@ -208,18 +208,21 @@ class ScriptMagics(Magics, Configurable): try: out, err = p.communicate(cell) except KeyboardInterrupt: - p.send_signal(signal.SIGINT) - time.sleep(0.1) - if p.poll() is not None: - print "Process is interrupted." - return - p.terminate() - time.sleep(0.1) - if p.poll() is not None: - print "Process is terminated." - return - p.kill() - print "Process is killed." + try: + p.send_signal(signal.SIGINT) + time.sleep(0.1) + if p.poll() is not None: + print "Process is interrupted." + return + p.terminate() + time.sleep(0.1) + if p.poll() is not None: + print "Process is terminated." + return + p.kill() + print "Process is killed." + except: + print "Failed to kill process properly (pid={0})".format(p.pid) return out = py3compat.bytes_to_str(out) err = py3compat.bytes_to_str(err)