Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

options.add_argument("--disable-gpu") potentially fixes zombie processes not being closed properly. #1723

Open
11AnJo opened this issue Jan 11, 2024 · 7 comments

Comments

@11AnJo
Copy link

11AnJo commented Jan 11, 2024

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.

@FRIKIdelTO
Copy link

FRIKIdelTO commented Jan 12, 2024

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>

@11AnJo
Copy link
Author

11AnJo commented Jan 12, 2024

@FRIKIdelTO
Did you tried #1507 (comment) ?

@11AnJo 11AnJo changed the title options.add_argument("--disable-gpu") fixes zombie processes not being closed properly. options.add_argument("--disable-gpu") potentially fixes zombie processes not being closed properly. Jan 12, 2024
@FRIKIdelTO
Copy link

@FRIKIdelTO Did you tried #1507 (comment) ?

I just tried it now and the problem is still there

@bigcharl
Copy link

It solved on my end too, I was using this nuclear option
#1667 (comment)

will try for a couple days to see if it's a long-term solution

@FRIKIdelTO
Copy link

FRIKIdelTO commented Jan 13, 2024

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

@ifeldshteyn
Copy link

ifeldshteyn commented Mar 9, 2024

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 ?

@0x1991
Copy link

0x1991 commented May 4, 2024

The only way I fixed this issue was calling close() before quit() like:

driver.close()
driver.quit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants