From e9346f6b8228dfe469a702674f447ba53915f519 Mon Sep 17 00:00:00 2001 From: steffen123 Date: Sat, 10 Jul 2010 20:10:04 +0200 Subject: [PATCH] make it record source of lock holding, print if required this is mostly intended for devs --- pyfpdb/GuiBulkImport.py | 2 +- pyfpdb/fpdb.pyw | 10 ++++++---- pyfpdb/interlocks.py | 9 ++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pyfpdb/GuiBulkImport.py b/pyfpdb/GuiBulkImport.py index a25db1d2..83f841e2 100755 --- a/pyfpdb/GuiBulkImport.py +++ b/pyfpdb/GuiBulkImport.py @@ -50,7 +50,7 @@ class GuiBulkImport(): ttime = None # Does the lock acquisition need to be more sophisticated for multiple dirs? # (see comment above about what to do if pipe already open) - if self.settings['global_lock'].acquire(False): # returns false immediately if lock not acquired + if self.settings['global_lock'].acquire(wait=False, source="GuiBulkImport"): # returns false immediately if lock not acquired #try: print "\nGlobal lock taken ..." self.progressbar.set_text("Importing...") diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index d734e418..fc5e9fb6 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -814,12 +814,13 @@ class fpdb: def not_implemented(self, widget, data=None): self.warning_box("Unimplemented menu entry") - def obtain_global_lock(self): - ret = self.lock.acquire(False) # will return false if lock is already held + def obtain_global_lock(self, source): + ret = self.lock.acquire(source=source) # will return false if lock is already held if ret: - print "\nGlobal lock taken ..." + print "\nGlobal lock taken by", source + self.lockTakenBy=source else: - print "\nFailed to get global lock." + print "\nFailed to get global lock, it is currently held by", source return ret # need to release it later: # self.lock.release() @@ -841,6 +842,7 @@ class fpdb: def release_global_lock(self): self.lock.release() + self.lockTakenBy=None print "Global lock released.\n" def tab_auto_import(self, widget, data=None): diff --git a/pyfpdb/interlocks.py b/pyfpdb/interlocks.py index 4e427e7d..f6ef7857 100755 --- a/pyfpdb/interlocks.py +++ b/pyfpdb/interlocks.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Code from http://ender.snowburst.org:4747/~jjohns/interlocks.py # Thanks JJ! @@ -34,19 +35,24 @@ class InterProcessLockBase: if not name: name = sys.argv[0] self.name = name + self.heldBy = None def getHashedName(self): return base64.b64encode(self.name).replace('=','') def acquire_impl(self, wait): abstract - def acquire(self, wait=False, retry_time=1): + def acquire(self, wait=False, retry_time=1, source=None): + if source == None: + source="Unknown" if self._has_lock: # make sure 2nd acquire in same process fails + print "lock already held by:",self.heldBy return False while not self._has_lock: try: self.acquire_impl(wait) self._has_lock = True + self.heldBy=source #print 'i have the lock' except SingleInstanceError: if not wait: @@ -58,6 +64,7 @@ class InterProcessLockBase: def release(self): self.release_impl() self._has_lock = False + self.heldBy=None def locked(self): if self.acquire():