Skip to content

Commit cee2b15

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 c0658d5 commit cee2b15

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
@@ -719,21 +719,25 @@ def login(self):
719719
raise xs_errors.XenError(msg) from exc
720720
return session
721721

722-
def logout(self, log="logout"):
722+
def _logout(self, log):
723+
"""Closes an API session"""
723724
if self.session is None:
724725
SMlog("APISession [{}] session is None {}".format(self.originator, log))
725726
return
726727
self.session.xenapi.session.logout()
727728
SMlog("APISession [{}] {}".format(self.originator, log))
728729
self.session = None
729730

730-
def __del__(self):
731-
"""Closes an API session"""
731+
def logout(self, log="logout"):
732732
atexit.unregister(self.atexit)
733-
self.logout(log="logout del")
733+
self._logout(log=log)
734+
735+
def __del__(self):
736+
if self.session:
737+
self.logout(log="logout del")
734738

735739
def atexit(self):
736-
self.logout(log="logout atexit")
740+
self._logout(log="logout atexit")
737741

738742
def __enter__(self):
739743
return self.session

0 commit comments

Comments
 (0)