(20251122) Added a staticmethod to kill all running Chrome processes before starting the automation script.
This commit is contained in:
@@ -38,6 +38,7 @@ sys.path.append("..")
|
|||||||
|
|
||||||
# For system-level activities:
|
# For system-level activities:
|
||||||
import os
|
import os
|
||||||
|
import psutil
|
||||||
|
|
||||||
# To work with date and time:
|
# To work with date and time:
|
||||||
import time
|
import time
|
||||||
@@ -201,6 +202,40 @@ class CosecWeb:
|
|||||||
self._printer.disable()
|
self._printer.disable()
|
||||||
self._nc_printer.disable()
|
self._nc_printer.disable()
|
||||||
|
|
||||||
|
# ┏┓ ┓┏┓•┓┓
|
||||||
|
# ┃┃┏┓┏┓┏┏┓┏┏ ┃┫ ┓┃┃
|
||||||
|
# ┣┛┛ ┗┛┗┗ ┛┛ ┛┗┛┗┗┗
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def kill_chrome_processes() -> int:
|
||||||
|
|
||||||
|
"""
|
||||||
|
To kill previous Chrome-driver processes. Use this when you think that older processes are going to interfere
|
||||||
|
with new ones.
|
||||||
|
:return: The count of the processes that were killed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
kill_count = 0
|
||||||
|
|
||||||
|
# Enlist all the processes:
|
||||||
|
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
|
||||||
|
|
||||||
|
# Try to kill the process:
|
||||||
|
try:
|
||||||
|
name = proc.info['name']
|
||||||
|
cmd = proc.info['cmdline']
|
||||||
|
if name and ('chrome' in name.lower() or 'chromedriver' in name.lower()):
|
||||||
|
# self._nc_printer("Killing Chrome Proc.", name, proc.pid, cmd)
|
||||||
|
proc.kill()
|
||||||
|
kill_count += 1
|
||||||
|
|
||||||
|
# In case of exceptions:
|
||||||
|
except (psutil.NoSuchProcess, psutil.AccessDenied): pass
|
||||||
|
|
||||||
|
# Done here:
|
||||||
|
# self._nc_printer("Killed Chrome Procs.", kill_count)
|
||||||
|
return kill_count
|
||||||
|
|
||||||
# ┳┳┓•
|
# ┳┳┓•
|
||||||
# ┃┃┃┓┏┏
|
# ┃┃┃┓┏┏
|
||||||
# ┛ ┗┗┛┗
|
# ┛ ┗┗┛┗
|
||||||
|
|||||||
Reference in New Issue
Block a user