undetected-chromedriver
undetected-chromedriver copied to clipboard
options.add_argument("--disable-gpu") potentially fixes zombie processes not being closed properly.
A lot of people including me had a problem with chrome processes not being closed correctly sometimes.
I found out that adding options.add_argument("--disable-gpu")
fixes it.
I don't really know what to do with that because I am not an expert but I just spent all day looking for answers and that fixed it for me. Hope that could help somebody.
I have the same problem and after trying what you mentioned, the problem is still there. I don't know what to do anymore... I've even tried use_subprocess=False and it doesn't solve either.
ps -ef | grep -v grep | grep defunct
frikide+ 31066 31012 0 10:13 pts/1 00:00:00 [chromedriver] <defunct>
frikide+ 31313 31012 0 10:13 pts/1 00:00:00 [chromedriver] <defunct>
frikide+ 31923 31012 16 10:15 pts/1 00:00:06 [chromium-browse] <defunct>
frikide+ 31925 31012 0 10:15 pts/1 00:00:00 [chromedriver] <defunct>
frikide+ 32152 31012 23 10:15 pts/1 00:00:05 [chromium-browse] <defunct>
frikide+ 32166 31012 1 10:15 pts/1 00:00:00 [chromedriver] <defunct>
@FRIKIdelTO Did you tried https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/1507#issuecomment-1694627996 ?
It solved on my end too, I was using this nuclear option https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/1667#issuecomment-1847275773
will try for a couple days to see if it's a long-term solution
Finally solved with this function (copy/paste and modified from seleniumbase):
def quit_driver(driver):
try:
os.kill(driver.browser_pid, 15)
if "linux" in sys.platform:
os.waitpid(driver.browser_pid, 0)
time.sleep(0.02)
else:
time.sleep(0.04)
except:
pass
if hasattr(driver, "service") and getattr(driver.service, "process", None):
driver.service.stop()
try:
if driver.reactor and isinstance(driver.reactor, Reactor):
driver.reactor.event.set()
except:
pass
if (
hasattr(driver, "keep_user_data_dir")
and hasattr(driver, "user_data_dir")
and not driver.keep_user_data_dir
):
import shutil
for _ in range(5):
try:
shutil.rmtree(driver.user_data_dir, ignore_errors=False)
except FileNotFoundError:
pass
else:
break
time.sleep(0.1)
driver.patcher = None
Finally solved with this function (copy/paste and modified from seleniumbase):
def quit_driver(driver): try: os.kill(driver.browser_pid, 15) if "linux" in sys.platform: os.waitpid(driver.browser_pid, 0) time.sleep(0.02) else: time.sleep(0.04) except: pass if hasattr(driver, "service") and getattr(driver.service, "process", None): driver.service.stop() try: if driver.reactor and isinstance(driver.reactor, Reactor): driver.reactor.event.set() except: pass if ( hasattr(driver, "keep_user_data_dir") and hasattr(driver, "user_data_dir") and not driver.keep_user_data_dir ): import shutil for _ in range(5): try: shutil.rmtree(driver.user_data_dir, ignore_errors=False) except FileNotFoundError: pass else: break time.sleep(0.1) driver.patcher = None
I just want to say this is the ONLY solution that worked. Everyone here is talking about just killing the process while the problem is clearly a file lock which prevents the defunct process from being killed. So check your file descriptors folks. Can we get this patched ?
The only way I fixed this issue was calling close()
before quit()
like:
driver.close()
driver.quit()