Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple chrome processes after chromedriver.quit()

I am running a Django service that fires up a chromedriver for selenium and scrapes a website for data. The Django service is called by another Java service through HTTP.

Here is the code:

views.py

path_to_chromedriver = '/path/to/chromedriver' 
browser = webdriver.Chrome(executable_path = path_to_chromedriver)
try:
    response = get_data(browser)
except Exception as e:
    print str(e)
finally:
    browser.close()
    browser.quit()

scraper.py

get_data(browser)
    try:
        .
        .
        .
        for i in range(1,6):
            try:
                .
                .
                .
             return "success data"
             except NoSuchElementException:
                 browser.back()
         raise Exception("No results found")
    except Exception as e:
         print str(e)
         raise

The problem is that after the java service has finished making all the calls and the whole process is complete, there are between 25 - 50 chrome processes orphaned in RAM occupying over 1 GB. Is there anything wrong I'm doing here?

like image 566
Anirudh Avatar asked Jan 19 '17 14:01

Anirudh


People also ask

Why do I have multiple Google Chrome processes running?

You may have noticed that Google Chrome will often have more than one process open, even if you only have one tab open. This occurs because Google Chrome deliberately separates the browser, the rendering engine, and the plugins from each other by running them in separate processes.

Why are there so many Chrome processes in Task Manager?

But if you open the Task Manager, you may be surprised to see many Google Chrome processes running. I could see 18 running even though I had opened only in one single window with 4 tabs. This is because Chrome opens a separate process for each of its tab, extension, tab and, subframe.

How do you close all Chrome processes?

Click the “≡” button in the upper right corner of the Chrome browser window. Select the Exit button. This will close all tabs and windows and end the process.


1 Answers

That's an old issue. What works for me, although dirty, is to add a sleep before quitting:

time.sleep(5)
browser.quit()
like image 186
Ivan Chaer Avatar answered Sep 18 '22 11:09

Ivan Chaer