Ignore processes that have disappeared by themselves
authorTollef Fog Heen <tfheen@err.no>
Mon, 6 May 2013 14:55:49 +0000 (16:55 +0200)
committerTollef Fog Heen <tfheen@err.no>
Mon, 6 May 2013 14:55:49 +0000 (16:55 +0200)
modules/buildd/files/buildd-schroot-aptitude-kill

index 220e9df..07f75c1 100755 (executable)
@@ -30,18 +30,21 @@ total_mem = psutil.phymem_usage().total
 cutoff_time = 60*10
 
 for p in psutil.process_iter():
-       if p.name != 'aptitude': continue
-       parent = p.parent
-       if parent is None: continue
-       if parent.name != 'schroot': continue
-       #
-       rootdir = os.readlink('/proc/%d/root'%(p.pid,))
-       if not rootdir.startswith('/var/lib/schroot/mount'): continue
-       #
-       used = p.get_memory_info().vms
-       if used < total_mem: continue
-       #
-       cputime = p.get_cpu_times().user
-       if cputime < cutoff_time: continue
-       #
-       p.kill()
+       try:
+               if p.name != 'aptitude': continue
+               parent = p.parent
+               if parent is None: continue
+               if parent.name != 'schroot': continue
+               #
+               rootdir = os.readlink('/proc/%d/root'%(p.pid,))
+               if not rootdir.startswith('/var/lib/schroot/mount'): continue
+               #
+               used = p.get_memory_info().vms
+               if used < total_mem: continue
+               #
+               cputime = p.get_cpu_times().user
+               if cputime < cutoff_time: continue
+               #
+               p.kill()
+       except psutil.error.NoSuchProcess:
+               pass