make it record source of lock holding, print if required

this is mostly intended for devs
This commit is contained in:
steffen123 2010-07-10 20:10:04 +02:00
parent ca61189706
commit e9346f6b82
3 changed files with 15 additions and 6 deletions

View File

@ -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...")

View File

@ -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):

View File

@ -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():