16 lines
464 B
Python
16 lines
464 B
Python
# 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() |