关闭Python中的Chrome并终止进程可以通过以下步骤实现:
import os
import psutil
import signal
def find_chrome_processes():
chrome_processes = []
for proc in psutil.process_iter(['pid', 'name']):
if proc.info['name'] == 'chrome.exe':
chrome_processes.append(proc)
return chrome_processes
def terminate_chrome_processes(chrome_processes):
for proc in chrome_processes:
try:
os.kill(proc.info['pid'], signal.SIGTERM)
except OSError:
pass
chrome_processes = find_chrome_processes()
terminate_chrome_processes(chrome_processes)
这样,Python中正在运行的Chrome进程将被关闭并终止。
领取专属 10元无门槛券
手把手带您无忧上云