ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.71k stars 1.14k forks source link

OSError: [WinError 6] The handle is invalid #955

Open evolvepx opened 1 year ago

evolvepx commented 1 year ago

Im getting this error when trying to run the following code: import undetected_chromedriver as uc driver = uc.Chrome() driver.get('https://google.com')

Exception ignored in: <function Chrome.__del__ at 0x00000215F7989A80>
Traceback (most recent call last):
  File "C:\Users\Paul Evolve\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
  File "C:\Users\Paul Evolve\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
OSError: [WinError 6] The handle is invalid
Exception ignored in: <function Patcher.__del__ at 0x00000215F7988EA0>
Traceback (most recent call last):
  File "C:\Users\Paul Evolve\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\patcher.py", line 273, in __del__
OSError: [WinError 6] The handle is invalid
timbeh commented 1 year ago

Same here... Been having it now and then for a few weeks, was too lazy to try and fix it, but now it kinda starts being annoying having to restart scripts all day.

Edit: As it's probably a problem with subprocessing it might have already gotten resolved with v3.1.7 Let's see if I get any crashes until tomorrow morning...

Drygord commented 1 year ago

Just got this error today. Also, it took a ridiculously long time to load up the browsers. Probably over a minute each. I don't get this issue with firefox as the webdriver.

evolvepx commented 1 year ago

modify import undetected_chromedriver as uc to import undetected_chromedriver.v2 as uc

timbeh commented 1 year ago

Thought it got solved, but just had a crash again... Updating to 3.1.7 did not resolve the issue, neither did what @evolvepx proposed (to add ".v2" in the import).

I'll attach the console output below. The crash was caused by this line: driver = uc.Chrome(version_main=installed_chromeVersion, options=chrome_options)

Traceback (most recent call last):
File "C:\Users\timbe\Desktop\ProjectFolder\ScriptTitle.py", line 410, in <module>
    driver = uc.Chrome(version_main=installed_chromeVersion, options=chrome_options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 429, in __init__
    super(Chrome, self).__init__(
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    super().__init__(
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 106, in __init__
    super().__init__(
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 715, in start_session
    super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:[58561](tel:58561)
from chrome not reachable
Stacktrace:
Backtrace:
        (No symbol) [0x0058F243]
        (No symbol) [0x00517FD1]
        (No symbol) [0x0040CF10]
        (No symbol) [0x00402B0A]
        (No symbol) [0x0042F04E]
        (No symbol) [0x00428424]
        (No symbol) [0x00428201]
        (No symbol) [0x0045F056]
        (No symbol) [0x0045EB2A]
        (No symbol) [0x00458386]
        (No symbol) [0x0043163C]
        (No symbol) [0x0043269D]
        GetHandleVerifier [0x00829A22+2655074]
        GetHandleVerifier [0x0081CA24+2601828]
        GetHandleVerifier [0x00638C0A+619850]
        GetHandleVerifier [0x00637830+614768]
        (No symbol) [0x005205FC]
        (No symbol) [0x00525968]
        (No symbol) [0x00525A55]
        (No symbol) [0x0053051B]
        BaseThreadInitThunk [0x75F000F9+25]
        RtlGetAppContainerNamedObjectPath [0x77897BBE+286]
        RtlGetAppContainerNamedObjectPath [0x77897B8E+238]

Exception ignored in: <function Chrome.__del__ at 0x000001A6668B3B00>
Traceback (most recent call last):
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
    self.quit()
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
    time.sleep(0.1)
OSError: [WinError 6] The handle is invalid

Something interesting: The part below was repeated like 20 times.

Exception ignored in: <function Chrome.__del__ at 0x000001A6668B3B00>
Traceback (most recent call last):
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
    self.quit()
  File "C:\Users\timbe\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
    time.sleep(0.1)
OSError: [WinError 6] The handle is invalid
timbeh commented 1 year ago

Found some related issues to it:

It seems like the OSError: [WinError 6] The handle is invalid has actually nothing to do with the issues themselves and is probably just Windows trying to close down a nonexistent chromedriver session.

In my case I will now try the different solutions from the issues mentioned above for cannot connect to chrome at 127.0.0.1:[58561] which is the actual issue in my case.

Edit: Merry Christmas everyone :)

chinwubing commented 1 year ago

Got the same error on version 3.1.7. Even if I change to import undetected_chromedriver.v2 as uc, the problem still exists.

timbeh commented 1 year ago

Got the same error on version 3.1.7. Even if I change to import undetected_chromedriver.v2 as uc, the problem still exists.

@chinwubing What's your full console output regarding the error?

sufianadnan commented 1 year ago

i seem to have the same thing tried the .v2 thing but no shot if you read the updates the v2 thing is no longer required its the new v1 ### EDIT: I WAS ABLE TO FIX IT, PYTHON 3.11 WAS THE ISSUE, Running Python 3.9.13 works fine


Exception ignored in: <function Chrome.__del__ at 0x0000024E66570360>
Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
    self.quit()
  File "C:\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
    time.sleep(0.1)
OSError: [WinError 6] The handle is invalid
Exception ignored in: <function Patcher.__del__ at 0x0000024E6656B7E0>
Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\undetected_chromedriver\patcher.py", line 273, in __del__
    time.sleep(0.1)
OSError: [WinError 6] The handle is invalid```
chinwubing commented 1 year ago

Got the same error on version 3.1.7. Even if I change to import undetected_chromedriver.v2 as uc, the problem still exists.

@chinwubing What's your full console output regarding the error? This is what I got in the output: ['CDwindow-1366722711AD866B1B8BF5B8A2B1410D'] Exception ignored in: <function Chrome.__del__ at 0x0000027460CFD760> Traceback (most recent call last): File "C:\projects\venv\invest\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__ File "C:\projects\venv\invest\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit OSError: [WinError 6] The handle is invalid

Drygord commented 1 year ago

i seem to have the same thing tried the .v2 thing but no shot if you read the updates the v2 thing is no longer required its the new v1 ### EDIT: I WAS ABLE TO FIX IT, PYTHON 3.11 WAS THE ISSUE, Running Python 3.9.13 works fine

Exception ignored in: <function Chrome.__del__ at 0x0000024E66570360>
Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
    self.quit()
  File "C:\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
    time.sleep(0.1)
OSError: [WinError 6] The handle is invalid
Exception ignored in: <function Patcher.__del__ at 0x0000024E6656B7E0>
Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\undetected_chromedriver\patcher.py", line 273, in __del__
    time.sleep(0.1)
OSError: [WinError 6] The handle is invalid```

I run Python 3.9 and get the issue.

sufianadnan commented 1 year ago

are you using driver.close() or driver.quit() try changing between them and see if that helps

zax2002 commented 1 year ago

I'm getting the error with Python 3.9 and 3.11 but for 3.10.7 everything works fine

Carlos-OL commented 1 year ago

Same issue. Just testing UC for the first time today and as soon as the browser opens it closes back again. I get the same:

Exception ignored in: <function Chrome.del at 0x000002C997BFC400> Traceback (most recent call last): File "G:\My Drive...\venv\Lib\site-packages\undetected_chromedriver__init.py", line 777, in del__ File "G:\My Drive...\venv\Lib\site-packages\undetected_chromedriver__init__.py", line 732, in quit OSError: [WinError 6] The handle is invalid

sufianadnan commented 1 year ago

i use Python 3.9.13 works perfectly fine, try using that if you want

Carlos-OL commented 1 year ago

Thanks. I just swapped my interpreter to 3.9 and I do not get the error, but still my browser is closing almost immediately. I was having that issue with the original selenium webdriver and I had to change some options. But those are not working with UC. Any ideas?

sufianadnan commented 1 year ago

hmm send the beginning of ur code to open browser and make sure your chrome is on latest and this is what i use


from selenium.webdriver.common.by import By  # locate elements
from selenium.webdriver.chrome.options import Options
import undetected_chromedriver as uc
    options = Options()
    driver = uc.Chrome(options=options)
g-l-i-t-c-h-o-r-s-e commented 1 year ago

mine crashes with all 3.9 and 3.11 3.10.7, none worked. Same error


Exception ignored in: <function Chrome.__del__ at 0x0000017C5A90A200>
Traceback (most recent call last):
  File "C:\Users\user\uc\undetected-chromedriver\undetected_chromedriver\__init__.py", line 777, in __del__
  File "C:\Users\user\uc\undetected-chromedriver\undetected_chromedriver\__init__.py", line 732, in quit
OSError: [WinError 6] The handle is invalid```
Carlos-OL commented 1 year ago

hmm send the beginning of ur code to open browser and make sure your chrome is on latest and this is what i use

from selenium.webdriver.common.by import By  # locate elements
from selenium.webdriver.chrome.options import Options
import undetected_chromedriver as uc
    options = Options()
    driver = uc.Chrome(options=options)

Thank you @sufianadnan I have the exact same code as you, still the browser opens and then closes on its own

import undetected_chromedriver as uc from selenium.webdriver.chrome.options import Options

options = Options() driver = uc.Chrome(options=options) driver.get("https://nowsecure.nl/")

g-l-i-t-c-h-o-r-s-e commented 1 year ago

I wonder if it has anything to do with lastest version of chromedriver not matching current chrome version https://chromedriver.storage.googleapis.com/LATEST_RELEASE

ManiMozaffar commented 1 year ago

Fixed in #1031

Carlos-OL commented 1 year ago

Just tested again on 3.11 and still doesnt work. Same error. But when I change my interpreter to 3.09 it does work. any ideas? @ManiMozaffar

ManiMozaffar commented 1 year ago

Just tested again on 3.11 and still doesnt work. Same error. But when I change my interpreter to 3.09 it does work. any ideas? @ManiMozaffar

Please use my repo code, perhaps. I'm running on python 3.11, and I had this issue, but using this repo I gave you I don't have any issue.

Carlos-OL commented 1 year ago

Just tested again on 3.11 and still doesnt work. Same error. But when I change my interpreter to 3.09 it does work. any ideas? @ManiMozaffar

Please use my repo code, perhaps. I'm running on python 3.11, and I had this issue, but using this repo I gave you I don't have any issue.

Thanks, where can I find your repo code? Sorry, I don't see any and I am fairly new to this. Trying to figure things out

27freeman commented 1 year ago

Whats the solution to this issue . I am getting this issue now with undetected chromedriver

Kliammmm213 commented 1 year ago

Same

bitelchux commented 1 year ago

Same to me (I am trying to access tiktok with this code) import undetected_chromedriver as uc

driver = uc.Chrome() driver.get( 'https://www.tiktok.com' )

muhammad-mobeen commented 1 year ago

I have made a solution but I don't know if it's good, but it does fix the issue for me. In the init.py around lines 780 - 790 there is a function:-

def __del__(self):
        try:
            self.service.process.kill()
        except:  # noqa
            pass
        self.quit()

My solution is that I have scoped self.quit() inside except:

    def __del__(self):
        try:
            self.service.process.kill()
        except:  # noqa
            # pass
            self.quit()

I looked into the self.quit() and there I found the following:

def quit(self):
        try:
            self.service.process.kill()
            logger.debug("webdriver process ended")
        except (AttributeError, RuntimeError, OSError):
            pass
.
.
.

Here you can see self.service.process.kill() is again called inside try: Maybe this is causing the problem as this kill() function is being invoked two times now, once in __del__() and again in quit().

Also, note my analysis is rookie and needs some insights from the developers here 😄.

muhammad-mobeen commented 1 year ago

Update

I have also found that commenting the time.sleep(0.1) inside def quit(self): also removes the error. I don't know why? But it does work🤷‍♂️

justfactINFO commented 1 year ago

does anyone have a solution to the problem, the fix from muhammad did nothing for me unfortunately, I get the error in the del method at line 272. I use Python 3.11

jquesgar commented 1 year ago

Having the same issue using Python 3.11.4.

Browser is closing almost instantly.

Chrome is updated to last version.

UPDATE: I see it is exactly the previous comment fix.

Solved it with the fix described here:

stackoverflow

_You can avoid this problem by modifying code in the undetectedchromedriver__init__.py.

Go to line 755 (it was not the line in my case) and wrap the time.sleep(0.1) with try-except block here is how the final code look like

try:
  time.sleep(0.1)
except OSError:
  pass
lawrencefchan commented 1 year ago

are you using driver.close() or driver.quit() try changing between them and see if that helps

Works for me on 3.11.2. I was originally using driver.quit() but driver.close() seems to avoid the issue.

sh-erfan commented 1 year ago

are you using driver.close() or driver.quit() try changing between them and see if that helps

This solved my problem. I only used close() and works fine. Thanks Python version: 3.11.0

mtomassoli commented 1 year ago

Nothing worked for me on a consistent basis, so I just suppressed the exception:

import undetected_chromedriver as uc

def suppress_exception_in_del(uc):
    old_del = uc.Chrome.__del__

    def new_del(self) -> None:
        try:
            old_del(self)
        except:
            pass

    setattr(uc.Chrome, '__del__', new_del)

suppress_exception_in_del(uc)

You might want to be more specific in your except clause.

Meihb commented 1 year ago

Nothing worked for me on a consistent basis, so I just suppressed the exception:

import undetected_chromedriver as uc

def suppress_exception_in_del(uc):
    old_del = uc.Chrome.__del__

    def new_del(self) -> None:
        try:
            old_del(self)
        except:
            pass

    setattr(uc.Chrome, '__del__', new_del)

suppress_exception_in_del(uc)

You might want to be more specific in your except clause.

works for me.thanks alot

Drygord commented 1 year ago

Does anyone in the email chain actually have a working version of Undetected Chromedriver? I could never consistently get it to work.

What version of Selenium is it stable on?

On Mon, Jul 31, 2023 at 5:14 PM Meihb @.***> wrote:

Nothing worked for me on a consistent basis, so I just suppressed the exception:

import undetected_chromedriver as uc def suppress_exception_in_del(uc): old_del = uc.Chrome.del

def new_del(self) -> None:
    try:
        old_del(self)
    except:
        pass

setattr(uc.Chrome, '__del__', new_del)

suppress_exception_in_del(uc)

You might want to be more specific in your except clause.

works for me.thanks alot

— Reply to this email directly, view it on GitHub https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/955#issuecomment-1659499803, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXUNOOSTKZKKFUTHDKLC6Z3XTBYAVANCNFSM6AAAAAATCNSE6I . You are receiving this because you commented.Message ID: @.*** com>

mtomassoli commented 1 year ago

Does anyone in the email chain actually have a working version of Undetected Chromedriver? I could never consistently get it to work. What version of Selenium is it stable on?

I'm using selenium 4.9.1. If you patch uc before actually using it, it should work, ... unless you're getting a crash somewhere else in uc.

nicobrb commented 1 year ago

I solved it! Just use time.sleep(1) under driver.close() and it's gonna close just fine. The problem is that the object is destroyed while code is waiting.

mtomassoli commented 1 year ago

I solved it! Just use time.sleep(1) under driver.close() and it's gonna close just fine. The problem is that the object is destroyed while code is waiting.

If you add driver.quit() after that, it stops working. Also, it doesn't work with driver.quit() alone. Finally, are we sure a delay of 1 second is always enough?

I still recommend my approach, which always works.

Drygord commented 1 year ago

Is this patch available through the UC github? Where does one find it

On Tuesday, August 1, 2023, Massimiliano Tomassoli @.***> wrote:

Does anyone in the email chain actually have a working version of Undetected Chromedriver? I could never consistently get it to work. What version of Selenium is it stable on?

I'm using selenium 4.9.1. If you patch uc before actually using it, it should work, ... unless you're getting a crash somewhere else in uc.

— Reply to this email directly, view it on GitHub https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/955#issuecomment-1660459896, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXUNOOQ2F2PBVSNJOZ4LM7LXTEIBVANCNFSM6AAAAAATCNSE6I . You are receiving this because you commented.Message ID: @.*** om>

mtomassoli commented 1 year ago

Is this patch available through the UC github? Where does one find it

See my post above.

yuliyaosipava commented 1 year ago

import undetected_chromedriver as uc

def suppress_exception_in_del(uc): old_del = uc.Chrome.del

def new_del(self) -> None:
    try:
        old_del(self)
    except:
        pass

setattr(uc.Chrome, '__del__', new_del)

suppress_exception_in_del(uc)

thanks a lot for this answer. It help me. Good luck!

ruangab commented 1 year ago

Eu fiz uma solução, mas não sei se é bom, mas resolvo o problema para mim. Não existe uma função init .py nas linhas 780 - 790: -

def __del__(self):
        try:
            self.service.process.kill()
        except:  # noqa
            pass
        self.quit()

Minha é solução que eu olhei para self.quit()dentroexcept:

    def __del__(self):
        try:
            self.service.process.kill()
        except:  # noqa
            # pass
            self.quit()

Encontrei self.quit()o seguinte:

def quit(self):
        try:
            self.service.process.kill()
            logger.debug("webdriver process ended")
        except (AttributeError, RuntimeError, OSError):
            pass
.
.
.

Aqui você pode ver self.service.process.kill()que é chamado novamente dentro. try: Talvez isso esteja causando o problema, pois esta kill()função está sendo invocada duas vezes agora, uma vez em __del__()e novamente em quit().

Além disso, observe que minha análise é novata e precisa de alguns insights dos desenvolvedores aqui 😄.

I did it here and it worked. Are there any updates to the module? Is it fixed yet?

worrawut289 commented 11 months ago

I solved it! Just use time.sleep(1) under driver.close() and it's gonna close just fine. The problem is that the object is destroyed while code is waiting.

I tried adding time.sleep(1) under driver.close() and it really worked.😄

AyalSwaid commented 7 months ago

I solved it by:

  1. changing python version from 3.11 into 3.9 (looks like the version depends on ur computer).
  2. used lower version and specifying the exact driver path: uc.Chrome(version_main=120, driver_executable_path=d_path)
xxxxxxbox commented 6 months ago

I had the same problem and solved it this way:

import undetected_chromedriver as uc_orig

# Make a new class from uc_orig.Chrome and redefine quit() function to suppress OSError
class Chrome(uc_orig.Chrome):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def quit(self):
        try:
            super().quit()
        except OSError:
            pass

if __name__ == "__main__":
    driver = Chrome(headless=False, use_subprocess=False)
    driver.get("https://nowsecure.nl")
    driver.save_screenshot("nowsecure2.png")
acdc7777 commented 5 months ago

changer comment self.quit()
its work

JacksonSouzaTR commented 5 months ago

I solve using psutil process = psutil.Process(driver.browser_pid) process.terminate()

Drygord commented 4 months ago

Hey all,

Does anyone here have Leon's contact info? ultrafunkamsterdamThe author undetected-chromedriver.

Thanks

On Mon, May 6, 2024 at 10:02 AM Tayyab Elahi @.***> wrote:

I have an interesting issue on my side. Looping on a bunch of links works fine in Jupyter Notebook doesn't crash but when I put my whole code in .py file and try to run in a clean manner by putting main lines of code in main function it crashes after getting 3 links. My chrome driver code is: def get_driver(): try: options = webdriver.ChromeOptions() driver = uc.Chrome(driver_executable_path="chromedriver.exe", options=options, version_main=120) driver.get("https://tonybet.com/nz/live/football") return driver except Exception as e: print("Error in get_driver: ", e)

I mentioned version_main after referring to this article. Using windows11, python 3.12

Can anybody help try some of above solution of overriding class functions but didn't work. I am not using driver.quit or close anywhere in code.

— Reply to this email directly, view it on GitHub https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/955#issuecomment-2096808182, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXUNOOQZI4O2UC3BJJJGI23ZA7OUFAVCNFSM6AAAAAATCNSE6KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJWHAYDQMJYGI . You are receiving this because you commented.Message ID: @.*** com>

Mike-Ro commented 3 months ago

Temporary fix: https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/1051#issuecomment-2194716579

keksikaaa commented 2 months ago

Hello, the actual solution is as follows: In the file "init.py", there are two changes to the undetected-chromedriver library. First, in the "quit" function, you need to move "time.sleep(0.1)" inside the "try" block. Like this:

for _ in range(5):
    try:
        shutil.rmtree(self.user_data_dir, ignore_errors=False)
        time.sleep(0.1)
    except FileNotFoundError:
        pass
    except (RuntimeError, OSError, PermissionError) as e:
        logger.debug(
            "When removing the temp profile, a %s occured: %s\nretrying..."
            % (e.__class__.__name__, e)
        )
    else:
        logger.debug("successfully removed %s" % self.user_data_dir)
        break
    # time.sleep(0.1)

Next, in the "del" method, move "self.quit()" inside the "try".

def __del__(self):
    try:
        self.service.process.kill()
        self.quit()
    except:  # noqa
        pass
    # self.quit()

Note: This works even on Python version 3.12.0.