-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup_mac.py
More file actions
71 lines (56 loc) · 2.1 KB
/
Copy pathcleanup_mac.py
File metadata and controls
71 lines (56 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import psutil
import os
import signal
import time
import subprocess
def cleanup_placement_tracker_mac():
"""Aggressively clean up all Placement Tracker processes on macOS"""
# Get the current process ID to avoid killing ourselves
current_pid = os.getpid()
# First try using pkill
try:
subprocess.run(['pkill', '-f', 'Placement_Tr'], check=False)
subprocess.run(['pkill', '-f', 'placement_tracker'], check=False)
except:
pass
time.sleep(1)
# Then use psutil for more detailed cleanup
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
try:
if proc.pid == current_pid:
continue
name = proc.name().lower()
cmdline = ' '.join(proc.cmdline()).lower() if proc.cmdline() else ''
if 'placement' in name or 'placement' in cmdline:
print(f"Killing process: {proc.name()} (PID: {proc.pid})")
# Try different kill signals
try:
os.kill(proc.pid, signal.SIGTERM)
except:
pass
time.sleep(0.1)
try:
os.kill(proc.pid, signal.SIGKILL)
except:
pass
# If process still exists, try force kill
if psutil.pid_exists(proc.pid):
subprocess.run(['kill', '-9', str(proc.pid)], check=False)
except (psutil.NoSuchProcess, psutil.AccessDenied):
continue
# Final force kill using terminal commands
commands = [
"killall -9 Placement_Tracker",
"killall -9 Python",
"killall -9 python3",
"killall -9 pythonw",
]
for cmd in commands:
try:
subprocess.run(cmd.split(), check=False)
except:
pass
if __name__ == "__main__":
print("Starting aggressive macOS cleanup...")
cleanup_placement_tracker_mac()
print("Cleanup completed")