Home > Back-end >  Finding an issue in ending the python process
Finding an issue in ending the python process

Time:09-13

I have a script to run a webdriver in a headless mode. I'm observing that after the whole execution of the script, the process is still running.

Here's the imitation of the issue I'm facing.

from selenium import webdriver
from webbrowser import Chrome
from ssl import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options


class PythonOrg():

    def Setup(self):
        self.chrome_options = Options()
        self.chrome_options.add_argument("--headless")
        # self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) #not a headless
        self.driver = webdriver.Chrome(options=self.chrome_options)

    
    def GetLink(self):
        driver = self.driver
        driver.get('https://www.python.org')
        print(driver.title)
        driver.close()
        print('Closed the driver')


inst = PythonOrg()


inst.Setup()
inst.GetLink()

Note: This is just a replication of the issue from the actual project.

Help me understand how can I manage the process when it gets completed, I'm new to Python platform.

CodePudding user response:

There is two options for webdriver - quit() and close()

# Closes the current window
driver.close()

# All windows related to driver instance will quit
driver.quit()

Seems you are just closing the window, thus why the instance is still active. Use quit() to terminate the instance.

  • Related