[Python]: Somethings been bothering me for the past year and how can I fix it?

I use appium in Python, I’ve been using it for the past year to run some automation. However, every so often, when I want to turn off the service via a quit() call, appium hangs up for 5-10 minutes before stopping.

Here is how I start the driver:

    desired_caps = dict(
server_address = "" + str(self.appium_server.get_current_port()) + "/wd/hub"
self.driver = webdriver.Remote(server_address, desired_caps)

Here is how I start the AppiumService:

`self.service = AppiumService()`
`self.service.start(args=['--address', '', '-p', str(self.port)])`

And here is how I stop the service:


I only use three kinds of actions in Appium:
Take screenshot of entire device
Click x,y

It is also possible in my application for someone to start/stop the service several times.
My application can run endlessly, often 24 hours or more at a time. However, I restart the appium service (not driver) to what I call “clean” out the memory as the appium service can’t handle running more than a certain amount of time.

However, when the user wants to stop the service, I call driver.quit() - Every once in a while, the driver will hang for 5-10 minutes at the quit() call. And I have no idea why.

Any help would be appreciated. Several hundred people use my product and this is a common issue.

It is hardly possible to say anything without having any logs