From 9b2c602a1f3f5e7cd26fcc30abe7d5cbfd73eab1 Mon Sep 17 00:00:00 2001 From: ngosang Date: Sat, 10 Jun 2023 19:26:28 +0200 Subject: [PATCH] Kill dead Chrome processes in Windows --- src/undetected_chromedriver/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/undetected_chromedriver/__init__.py b/src/undetected_chromedriver/__init__.py index 85c88a4..29ef76a 100644 --- a/src/undetected_chromedriver/__init__.py +++ b/src/undetected_chromedriver/__init__.py @@ -729,6 +729,15 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver): logger.debug("gracefully closed browser") except Exception as e: # noqa logger.debug(e, exc_info=True) + # Force kill Chrome process in Windows + # https://github.com/FlareSolverr/FlareSolverr/issues/772 + if os.name == 'nt': + try: + subprocess.call(['taskkill', '/f', '/pid', str(self.browser_pid)], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + except Exception: + pass if ( hasattr(self, "keep_user_data_dir") and hasattr(self, "user_data_dir")