From 3fa9631559485ac484b9b1a8031f50956b36477f Mon Sep 17 00:00:00 2001 From: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com> Date: Mon, 13 Nov 2023 04:28:19 +0000 Subject: [PATCH] Fix "OSError: [WinError 6] The handle is invalid" on exit --- src/undetected_chromedriver/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/undetected_chromedriver/__init__.py b/src/undetected_chromedriver/__init__.py index 5ae4f4a..af92b73 100644 --- a/src/undetected_chromedriver/__init__.py +++ b/src/undetected_chromedriver/__init__.py @@ -811,7 +811,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