From 44cfee227aabd5db170b6f9071611dfa1cea76fc Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 21 Jul 2011 13:55:07 +0200 Subject: [PATCH] [molecule.utils] enhance kill_chroot_pids(), add ability to sleep and wait for scripts to leave "zombies" --- molecule/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/molecule/utils.py b/molecule/utils.py index 986c644..f086a19 100644 --- a/molecule/utils.py +++ b/molecule/utils.py @@ -111,11 +111,16 @@ def exec_chroot_cmd(args, chroot, pre_chroot = None, env = None): RUNNING_PIDS.discard(pid) return rc -def kill_chroot_pids(chroot, sig = signal.SIGTERM): +def kill_chroot_pids(chroot, sig = signal.SIGTERM, sleep = False): """ Kill stale processes inside chroot or directory """ args = ["/usr/bin/lsof", "-t", chroot] + if sleep: + # give time to failing stuff to fail definitely and spawn all the + # possible, processes. It is really hard to kill them all when there + # is bash involved. + time.sleep(5.0) sts, txt = exec_cmd_get_status_output(args) if sts == 0: killed_pids = [] @@ -129,6 +134,10 @@ def kill_chroot_pids(chroot, sig = signal.SIGTERM): killed_pids.append(pid) except (OSError, IOError): sts = 1 + if (sts == 0) and killed_pids: + time.sleep(2.0) + # are we done? nested call if not + return kill_chroot_pids(chroot, sig = sig, sleep = False) return sts else: return sts