singleinstance quality fixes

This commit is contained in:
lakshyacis 2019-10-22 19:54:20 +05:30
parent 503d0b33d0
commit b9ad6a3bac
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB
1 changed files with 5 additions and 4 deletions

View File

@ -16,7 +16,7 @@ except ImportError:
pass pass
class singleinstance: class singleinstance(object):
""" """
Implements a single instance application by creating a lock file Implements a single instance application by creating a lock file
at appdata. at appdata.
@ -40,6 +40,7 @@ class singleinstance:
atexit.register(self.cleanup) atexit.register(self.cleanup)
def lock(self): def lock(self):
"""Obtain single instance lock"""
if self.lockPid is None: if self.lockPid is None:
self.lockPid = os.getpid() self.lockPid = os.getpid()
if sys.platform == 'win32': if sys.platform == 'win32':
@ -52,8 +53,7 @@ class singleinstance:
self.lockfile, self.lockfile,
os.O_CREAT | os.O_EXCL | os.O_RDWR | os.O_TRUNC os.O_CREAT | os.O_EXCL | os.O_RDWR | os.O_TRUNC
) )
except OSError: except OSError as e:
type, e, tb = sys.exc_info()
if e.errno == 13: if e.errno == 13:
print( print(
'Another instance of this application' 'Another instance of this application'
@ -84,6 +84,7 @@ class singleinstance:
self.fp.flush() self.fp.flush()
def cleanup(self): def cleanup(self):
"""Release single instance lock"""
if not self.initialized: if not self.initialized:
return return
if self.daemon and self.lockPid == os.getpid(): if self.daemon and self.lockPid == os.getpid():
@ -94,7 +95,7 @@ class singleinstance:
os.close(self.fd) os.close(self.fd)
else: else:
fcntl.lockf(self.fp, fcntl.LOCK_UN) fcntl.lockf(self.fp, fcntl.LOCK_UN)
except Exception, e: except Exception:
pass pass
return return