import psutil import time marks = ('wave_seq.py', 'comet_cdp.py', 'wave_gmail.py', 'comet_wave_px.py') killed = [] for p in psutil.process_iter(['pid', 'name', 'cmdline']): try: if (p.info['name'] or '').lower() != 'python.exe': continue c = ' '.join(p.info['cmdline'] or []) if any(m in c for m in marks) and 'kill_comet.py' not in c: p.kill() killed.append(p.info['pid']) except Exception: pass time.sleep(1) c2 = 0 for p in psutil.process_iter(['pid', 'name', 'cmdline']): try: if (p.info['name'] or '').lower() != 'chrome.exe': continue c = ' '.join(p.info['cmdline'] or []) if 'cometapi' in c and 'prof' in c: p.kill() c2 += 1 except Exception: pass print('killed python:', killed) print('killed chrome:', c2)