Patch to DorothyLocker

Thomas Klaeger <[email protected]> Mon, 20 Sep 2004 12:41:20 +0200
Newsgroups gmane.comp.pythin.pyds.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------060902070901070300010301
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

DorothyLocker raised exceptions if a lock was held by another task. In 
this case the lockContext and lockTime was not defined although it 
should have been.

Additionally it whined about unable to lock long after the lock had been 
acquired due to the LockWhiner not checking if it has been stopped 
before whining.

--------------060902070901070300010301
Content-Type: text/plain;
 name="dorothy.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="dorothy.diff"

Index: PyDS/DorothyLocker.py
===================================================================
RCS file: /pyds/PyDS/PyDS/DorothyLocker.py,v
retrieving revision 1.2
diff -u -r1.2 DorothyLocker.py
--- PyDS/DorothyLocker.py	14 Sep 2004 08:51:06 -0000	1.2
+++ PyDS/DorothyLocker.py	20 Sep 2004 10:33:17 -0000
@@ -89,6 +89,8 @@
 			self.acquire.func_code, 
 			self.release.func_code,
 			self.callContext.func_code]
+		self.lockTime = 0
+		self.lockContext = None
 		
 	def callContext(self): 
 		"Distil our calling context, with instance-specific ignores."
@@ -134,7 +136,7 @@
 			result = _RLock.acquire(self, blocking=0)
 			if not result: 
 				# Whine whilst we wait for the lock to clear. 
-				whiner = LockWhiner(self, mycontext, myt, prevcontext, prevt)
+				whiner = LockWhiner(self, mycontext, myt, self.lockContext, self.lockTime)
 				whiner.start()
 				result = _RLock.acquire(self, blocking)
 				whiner.stop()
@@ -143,12 +145,15 @@
 			
 		if result: 
 			myLocks.append((mycontext, myt))
+			self.lockTime = time.time()
+			self.lockContext = mycontext
 
 		return result
 
 	def release(self): 
 		"""Release the lock, first checking that we're releasing from the 
 		same frame that acquired us."""
+		self.lockContext = []
 		result = _RLock.release(self) # raises AssertionError if not acquired in this thread
 		context = self.callContext()
 		me = currentThread()
@@ -193,7 +198,7 @@
 				print repr(row)
 
 	def _run(self): 
-		fun = self.whineContext[-1][2]
+		#fun = self.whineContext[-1][2]
 		print "%s: LockWhiner started by %s thread %d" % (\
 		      time.ctime(self.whineTime), 
 		      self.dorothy.name, 
@@ -201,6 +206,8 @@
 		waits = 0
 		while self.active: 
 			time.sleep(self.whineEvery)
+			if not self.active: # no longer active - don't output anything
+				return
 			waits = waits + 1
 			now = time.time()
 			print "%s: LockWhiner has been waiting for %.2fs" % (

--------------060902070901070300010301--