From e7382b7714947c69ad0427890bf4618ba3716ff9 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Fri, 28 Jul 2017 09:39:49 +0200 Subject: [PATCH] Write PID into the lock file --- src/singleinstance.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/singleinstance.py b/src/singleinstance.py index a6ac4552..d6337ff6 100644 --- a/src/singleinstance.py +++ b/src/singleinstance.py @@ -44,7 +44,7 @@ class singleinstance: # file already exists, we try to remove (in case previous execution was interrupted) if os.path.exists(self.lockfile): os.unlink(self.lockfile) - self.fd = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR) + self.fd = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR | os.O_TRUNC) except OSError: type, e, tb = sys.exc_info() if e.errno == 13: @@ -52,6 +52,9 @@ class singleinstance: sys.exit(-1) print(e.errno) raise + else: + pidLine = "%i\n" % self.lockPid + self.fd.write(pidLine) else: # non Windows self.fp = open(self.lockfile, 'w') try: @@ -63,6 +66,10 @@ class singleinstance: except IOError: print 'Another instance of this application is already running' sys.exit(-1) + else: + pidLine = "%i\n" % self.lockPid + self.fp.write(pidLine) + self.fp.flush() def cleanup(self): if not self.initialized: