請問有關atexit.register這個功能是不是一執行python就立即觸發預載了?
因為Ctrl+C都還沒送chrome視窗就被關閉了
這個問題要怎麼解呢?
謝謝
===================================================================
7/29修正
只要加了下文紅字區段,下Ctrr+C呼叫driver.quit()就會無效
import sys
import atexit
from selenium import webdriver
def cleanup_function():
driver.quit()
sys.exit(0)
atexit.register(cleanup_function)
url="http://google.com"
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
driver.get(url)
input("")
===================================================================
7/31更新 用此方法成功
import sys
import os
import atexit
import psutil
from selenium import webdriver
def cleanup_function():
for child in parray:
killpid="taskkill /f /pid "+('{}'.format(child.pid))
os.system(killpid)
sys.exit(0)
atexit.register(cleanup_function)
url="http://google.com"
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(options=options)
driver.get(url)
p = psutil.Process(driver.service.process.pid)
parray=p.children(recursive=True)
input("")