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

How do I free up all the resources? #1844

Open
sxl2016 opened this issue Apr 25, 2024 · 2 comments
Open

How do I free up all the resources? #1844

sxl2016 opened this issue Apr 25, 2024 · 2 comments

Comments

@sxl2016
Copy link

sxl2016 commented Apr 25, 2024

Recently, when I use undetected-chromewebdriver, it told me it only support chrome version 124.
So I upgrade chrome to 124.

But there is a issue. In the past version 123, I can use it create and destory 20 chrome.
In version 124, it only 5 or less. And my computer would becomes very slow. I must restart it.

Here is my simple code.

for i in range( 20):
mWevdriver = uc.Chrome(service = s, options=chrome_options, seleniumwire_options=wire_options)
mWevdriver.set_window_size(width, height)
mWevdriver.implicitly_wait(WEBDRIVER_ELEMENT_WAIT_TIME)
mWebwait = WebDriverWait(self.mWevdriver, WEBDRIVER_ELEMENT_WAIT_TIME)
mWevdriver.get(strWebPath)
mWevdriver.quit()

@sxl2016
Copy link
Author

sxl2016 commented Apr 25, 2024

in version 123, it also have problem.

Exception ignored in: <function Chrome.del at 0x000001CA57B21E40>
Traceback (most recent call last):
File "C:\Users\sxl6107\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver_init_.py", line 843, in del
self.quit()
File "C:\Users\sxl6107\AppData\Local\Programs\Python\Python311\Lib\site-packages\seleniumwire\webdriver.py", line 68, in quit
super().quit()
File "C:\Users\sxl6107\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver_init_.py", line 798, in quit
time.sleep(0.1)
OSError: [WinError 6]

@sxl2016
Copy link
Author

sxl2016 commented Apr 26, 2024

The issue with version 124 has been found.

The cause of the problem is quit() does not destroy all chrome processes.
It will leave two chrome processes unclosed.
So I simply used psutil to forcibly shut down these two processes.

Here is the code:

import psutil

def find_chrome_processes():
chrome_processes = []
for proc in psutil.process_iter(['name', 'pid', 'cmdline']):
if proc.info['name'] == 'chrome.exe' or proc.info['name'] == 'Google Chrome':
chrome_processes.append(proc)
return chrome_processes

    chrome_processes = find_chrome_processes()
    for proc in chrome_processes:
        if "--user-data-dir=C:\\Users" in ' '.join(proc.info['cmdline']):
            print(f"进程ID: {proc.info['pid']} killed")
            proc.kill()

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

1 participant