From b2878a6c31962d30894c7b9dea7196cc7238fe79 Mon Sep 17 00:00:00 2001 From: Tayler Porter Date: Sun, 10 Apr 2022 22:23:55 -0500 Subject: [PATCH] [FIX] Make SIPClient.stop more reliable. (Implement commit a886c3af9264d4b5b6e06da0b0b02b2d0f8a0324) --- pyVoIP/SIP.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pyVoIP/SIP.py b/pyVoIP/SIP.py index 5bd9867..41cdb8e 100644 --- a/pyVoIP/SIP.py +++ b/pyVoIP/SIP.py @@ -583,10 +583,16 @@ def start(self): def stop(self): self.NSD = False - self.registerThread.cancel() - self.deregister() - self.s.close() - self.out.close() + if self.registerThread: + self.registerThread.cancel() + self.deregister() + self._close_sockets() + + def _close_sockets(self): + if self.s: + self.s.close() + if self.out: + self.out.close() def genCallID(self): return hashlib.sha256(str(self.callID.next()).encode('utf8')).hexdigest()[0:32]+"@"+self.myIP+":"+str(self.myPort)