servermodel/server_2.py

16 lines
479 B
Python
Raw Normal View History

2024-08-25 12:20:21 +08:00
# stop_service.py
import subprocess
def stop_service():
# 查找 uvicorn 进程 ID
find_cmd = "ps aux | grep 'uvicorn server.main:app --reload' | grep -v grep | awk '{print $2}'"
process = subprocess.run(find_cmd, shell=True, capture_output=True, text=True)
pid = process.stdout.strip()
if pid:
# 终止进程
kill_cmd = f"kill {pid}"
subprocess.run(kill_cmd, shell=True)
if __name__ == '__main__':
stop_service()