I need to close the connection, but due to the instability of the OPC server, the close method is “hung up”.
I need some kind of either interruption or continuation of the thread execution.
I looked at the ability to implement using threading , but the suspicion crept in that the calling thread will not be closed until the run method is executed.
How to change this implementation so as not to create a memory leak?
import threading import OpenOPC class Worker(threading.Thread): def __init__(self, func): threading.Thread.__init__(self) self.daemon = True self.func = func def run(self): self.func.close() def test(): t = Worker(OpenOPC.connect('localhost')) t.start() t.join(5) return