Selenium kill process to release mem, supervisor conf rotate log file
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user