From 35c6e786efd26e1d473968c012ee9beee1f98d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enes=20G=C3=B6rkem=20Gen=C3=A7?= Date: Mon, 12 Jun 2023 22:47:57 +0300 Subject: [PATCH] Fix of "OSError: [WinError 6] The handle is invalid" This error seems to be a problem for a lot of users of the package. Adding a try-except block is solving the issue for them while keeping it functional for the others as well. Source: https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/955 --- undetected_chromedriver/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/undetected_chromedriver/__init__.py b/undetected_chromedriver/__init__.py index 2139c58..32724e4 100644 --- a/undetected_chromedriver/__init__.py +++ b/undetected_chromedriver/__init__.py @@ -782,7 +782,11 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver): else: logger.debug("successfully removed %s" % self.user_data_dir) break - time.sleep(0.1) + + try: + time.sleep(0.1) + except OSError: + pass # dereference patcher, so patcher can start cleaning up as well. # this must come last, otherwise it will throw 'in use' errors