Selenium kill process to release mem, supervisor conf rotate log file

This commit is contained in:
Luciano Gervasoni
2025-07-28 11:16:15 +02:00
parent 54e41139bb
commit 1502f09e22
4 changed files with 49 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
import psutil
def get_webdriver():
options = Options()
@@ -10,4 +11,13 @@ def get_webdriver():
service = Service('/usr/local/bin/geckodriver')
driver = webdriver.Firefox(options=options, service=service)
return driver
return driver, service
def kill_process_tree(pid):
try:
parent = psutil.Process(pid)
for child in parent.children(recursive=True):
child.kill()
parent.kill()
except psutil.NoSuchProcess:
pass