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

View File

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