First of all, I'd like to say this is a personal script and I am the only person who is ever going to run it.
I am writing a productivity program that blocks applications from running at a certain time, chrome is one of them. However, I do a lot of web scraping in a daily basis, so I need to 'whitelist' chromedriver from closing while the code is running.
This is how I'm using it:
import subprocess
imgNames = ["Chrome.exe"] # There are several processes on this list, not only chrome.
for img in imgNames:
subprocess.call(['taskkill', '/F', '/IM', img], shell=True)
Since chromedriver has the same .exe name, I'm thinking maybe there is a way of changing the process name or perhaps some other way of identifying it, so it stays open during the block sessions.
CodePudding user response:
You can adopt a strategy to exclude the list of whilelist_process
from the entire list of total_processes
as follows:
whilelist_process = "chromedriver.exe"
total_processes = ["Chrome.exe", ...] # There are several processes on this list, not only chrome.
kill_processes = [x for x in total_processes if x != whilelist_process]
for proc in kill_processes:
subprocess.call(['taskkill', '/F', '/IM', proc], shell=True)
CodePudding user response:
For anyone in the future facing the same problem: It's probably not the answer you were expecting, but I ended up using Firefox's geckodriver instead of chromedriver and now I'm able to kill the chromedriver and still have a selenium browser opened while the rest gets blocked.