I am using selenium to run a web scraping service. E.g.
class Scraper:
def __init__(self):
self.driver = webdriver.Chrome('drivers/chromedriver')
def __del__(self):
self.driver.close()
My superficial understanding of networking is that when we spin up a webdriver, we open a local TCP port that makes http requests to load webpages. I am also under the assumption that when we call self.driver.close, we can close that connection and free up our ports.
However, after working with this I've seen a ton of chromedriver instances still open on my computer. I ran sudo lsof -i -n -P | grep TCP
. What is going on? Is my understanding wrong?
If a program that opens this webdriver terminates, and I did not specify __del__
, will it be guaranteed to leave my connection open? If I do specify __del__
then will python handle closing the port?