Author: bugman Date: Sun Aug 7 22:34:25 2011 New Revision: 14243 URL: http://svn.gna.org/viewcvs/relax?rev=14243&view=rev Log: Created an object called Relax_lock to help debug locking issues in relax. The status.spin_lock lock is now using Relax_lock. Modified: branches/gui_testing/status.py Modified: branches/gui_testing/status.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/status.py?rev=14243&r1=14242&r2=14243&view=diff ============================================================================== --- branches/gui_testing/status.py (original) +++ branches/gui_testing/status.py Sun Aug 7 22:34:25 2011 @@ -69,7 +69,7 @@ self.pipe_lock = Lock() # The molecule, residue, spin structure lock object. - self.spin_lock = Lock() + self.spin_lock = Relax_lock() # The exception queue for handling exceptions in threads. self.exception_queue = Queue() @@ -340,6 +340,7 @@ return release + class Observer(object): """The observer design pattern base class.""" @@ -410,6 +411,80 @@ +class Relax_lock: + """A type of locking object for relax.""" + + def __init__(self, debug=True): + """Set up the lock-like object. + + @keyword debug: A flag which is True will allow this object to be debugged as the locking mechanism is turned off. + @type debug: bool + """ + + # Init a threading.Lock object. + self._lock = Lock() + + # Debugging. + self.debug = debug + if self.debug: + # Track the number of acquires. + self._lock_level = 0 + + + def acquire(self): + """Simulate the Lock.acquire() mechanism.""" + + # Debugging. + if self.debug: + # Write out. + sys.__stderr__.write('Acquire') + + # Increment the lock level. + self._lock_level += 1 + + # Throw an error. + if self._lock_level > 1: + raise + + # Return to prevent real locking. + return + + # Acquire the real lock. + lock = self._lock.acquire() + + # Return the real lock. + return lock + + + def locked(self): + """Simulate the Lock.locked() mechanism.""" + + # Call the real method. + return self._lock.locked() + + + def release(self): + """Simulate the Lock.release() mechanism.""" + + # Debugging. + if self.debug: + # Write out. + sys.__stderr__.write('Release') + + # Increment the lock level. + self._lock_level -= 1 + + # Return to prevent real lock release. + return + + # Release the real lock. + release = self._lock.release() + + # Return the status. + return release + + + class Status_container: """The generic empty container for the status data."""