Locking problems with DorothyLocker
"Thomas Klaeger" <[email protected]> Sat, 18 Sep 2004 22:07:17 +0200
| Newsgroups | gmane.comp.pythin.pyds.devel |
|---|---|
| Message-ID | <414CB195.6831.88D1DF@localhost> |
--Message-Boundary-10038
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body
-- This time with patches attached....
I started using the pyds version from cvs and noticed locking problems if I
started pyds with the verbose option.
To track down the problems I changed Tool.py at two places:
* the tool threads are created with the tool name as thread name
* the lock object (DorothyRLock) are created with verbose=True
After these changes I noticed that DorothyRLock did not always lock
correctly - it seemed to not block if a lock was already acquired by
another thread. To correct this I changed the second locking attempt to
_RLock.acquire(self, blocking=1)
This change removed most of the locking problems, however sometimes I had
an error message about prevcontext not being initialized. So I also added
some code to always initialize prevcontext to None.
Garth, as you have written DorothyLocker, could you please review these
patches and submit them to Georg?
Regards,
Thomas
--Message-Boundary-10038
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Text from file 'diff.txt'
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 18 Sep 2004 12:08:14 -0000
@@ -102,6 +102,7 @@
myLocks = self.__threads.setdefault(me, [])
mycontext, myt = self.callContext(), time.time()
+ prevcontext = None
# If there were any locks...
if myLocks:
# Try to figure out whether the previous lock should have been
@@ -136,7 +137,7 @@
# Whine whilst we wait for the lock to clear.
whiner = LockWhiner(self, mycontext, myt, prevcontext, prevt)
whiner.start()
- result = _RLock.acquire(self, blocking)
+ result = _RLock.acquire(self, blocking=1)
whiner.stop()
else:
result = _RLock.acquire(self, blocking=0)
Index: PyDS/Tool.py
===================================================================
RCS file: /pyds/PyDS/PyDS/Tool.py,v
retrieving revision 1.195
diff -u -r1.195 Tool.py
--- PyDS/Tool.py 14 Sep 2004 08:57:38 -0000 1.195
+++ PyDS/Tool.py 18 Sep 2004 11:49:09 -0000
@@ -1143,7 +1143,7 @@
self.rss = 0
self.hasAPI = 1
if _PyDS.verbose:
- self.lock = DorothyRLock()
+ self.lock = DorothyRLock(verbose=True)
else:
self.lock = threading.RLock()
self.lockedFrom = None
@@ -1334,6 +1334,7 @@
background = threading.Thread(
target=thunk,
+ name=self.name,
args=[self, status],
kwargs={}
)
--Message-Boundary-10038--