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?