From 0d52501157a721ad2d739e6d553537efdcf9630b 2017-03-25 20:34:20 From: Thomas Kluyver Date: 2017-03-25 20:34:20 Subject: [PATCH] Backport PR #10408: Speed up shutdown by eliminating unnecessary sleeping Eliminate an annoying split-second pause when closing a shell session by reducing unnecessary sleeps while killing background scripts. If there are no bacgkround scripts running, or if they shut down on the first or second attempt, then we can eliminate some pauses. --- diff --git a/IPython/core/magics/script.py b/IPython/core/magics/script.py index be8fa94..3fbddc3 100644 --- a/IPython/core/magics/script.py +++ b/IPython/core/magics/script.py @@ -246,6 +246,8 @@ class ScriptMagics(Magics): def kill_bg_processes(self): """Kill all BG processes which are still running.""" + if not self.bg_processes: + return for p in self.bg_processes: if p.poll() is None: try: @@ -253,6 +255,9 @@ class ScriptMagics(Magics): except: pass time.sleep(0.1) + self._gc_bg_processes() + if not self.bg_processes: + return for p in self.bg_processes: if p.poll() is None: try: @@ -260,6 +265,9 @@ class ScriptMagics(Magics): except: pass time.sleep(0.1) + self._gc_bg_processes() + if not self.bg_processes: + return for p in self.bg_processes: if p.poll() is None: try: