Skip to content

Commit 0ddd81a

Browse files
committed
unregister atexit on APISession:logout
Do not SMlog information when __del__ is called and the session has already been closed. Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
1 parent 431e79d commit 0ddd81a

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

drivers/util.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,21 +787,25 @@ def login(self):
787787
raise xs_errors.XenError(msg) from exc
788788
return session
789789

790-
def logout(self, log="logout"):
790+
def _logout(self, log):
791+
"""Closes an API session"""
791792
if self.session is None:
792793
SMlog("APISession [{}] session is None {}".format(self.originator, log))
793794
return
794795
self.session.xenapi.session.logout()
795796
SMlog("APISession [{}] {}".format(self.originator, log))
796797
self.session = None
797798

798-
def __del__(self):
799-
"""Closes an API session"""
799+
def logout(self, log="logout"):
800800
atexit.unregister(self.atexit)
801-
self.logout(log="logout del")
801+
self._logout(log=log)
802+
803+
def __del__(self):
804+
if self.session:
805+
self.logout(log="logout del")
802806

803807
def atexit(self):
804-
self.logout(log="logout atexit")
808+
self._logout(log="logout atexit")
805809

806810
def __enter__(self):
807811
return self.session

0 commit comments

Comments
 (0)