cluster4npu/kill_app_processes.py

66 lines
2.0 KiB
Python

"""
Kill any running app processes and clean up locks
"""
import psutil
import os
import sys
import time
def kill_python_processes():
"""Kill any Python processes that might be running the app"""
killed_processes = []
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
try:
# Check if it's a Python process
if 'python' in proc.info['name'].lower():
cmdline = proc.info['cmdline']
if cmdline and any('main.py' in arg for arg in cmdline):
print(f"Killing process: {proc.info['pid']} - {' '.join(cmdline)}")
proc.kill()
killed_processes.append(proc.info['pid'])
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
if killed_processes:
print(f"Killed {len(killed_processes)} Python processes")
time.sleep(2) # Give processes time to cleanup
else:
print("No running app processes found")
def clean_lock_files():
"""Remove any lock files that might prevent app startup"""
possible_lock_files = [
'app.lock',
'.app.lock',
'cluster4npu.lock',
os.path.expanduser('~/.cluster4npu.lock'),
'/tmp/cluster4npu.lock',
'C:\\temp\\cluster4npu.lock'
]
removed_files = []
for lock_file in possible_lock_files:
try:
if os.path.exists(lock_file):
os.remove(lock_file)
removed_files.append(lock_file)
print(f"Removed lock file: {lock_file}")
except Exception as e:
print(f"Could not remove {lock_file}: {e}")
if removed_files:
print(f"Removed {len(removed_files)} lock files")
else:
print("No lock files found")
if __name__ == '__main__':
print("Cleaning up app processes and lock files...")
print("=" * 50)
kill_python_processes()
clean_lock_files()
print("=" * 50)
print("Cleanup complete! You can now start the app with 'python main.py'")