Hi!
I am just diggin' through rc.py, and found this code:
# search for events in the queue
if len(self.queue):
self.lock.acquire()
ret = self.queue[0]
del self.queue[0]
self.lock.release()
return ret
I just want to notice that there is the theoretic possibility of a context
switch between the "if len(...):" and the lock.acquire(). In this case,
self.queue might be emptied by another thread(?) and accessing [0] later
(after this thread being activated again) would result in an exception.
(BTW: wouldn't the release() call be missing in that situation?)
I really do not know enough about Freevo's usage of the EventHandler, however
from reading the comment about thread-safety, I would propose one of the
attached patches (the _shorter one doing the acquire() before the len() call)
just to be sure.
--
Ciao, / / .o.
/--/ ..o
/ / ANS ooo
Index: rc.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/Attic/rc.py,v
retrieving revision 1.36.2.1
diff -u -3 -p -d -r1.36.2.1 rc.py
--- rc.py 20 Oct 2004 18:31:46 -0000 1.36.2.1
+++ rc.py 23 Nov 2004 22:03:25 -0000
@@ -497,10 +497,15 @@ class EventHandler:
# search for events in the queue
if len(self.queue):
self.lock.acquire()
- ret = self.queue[0]
- del self.queue[0]
- self.lock.release()
- return ret
+ try:
+ try:
+ ret = self.queue[0]
+ del self.queue[0]
+ return ret
+ except IndexError:
+ pass
+ finally:
+ self.lock.release()
# search all input objects for new events
for i in self.inputs:
Index: rc.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/Attic/rc.py,v
retrieving revision 1.36.2.1
diff -u -3 -p -d -r1.36.2.1 rc.py
--- rc.py 20 Oct 2004 18:31:46 -0000 1.36.2.1
+++ rc.py 23 Nov 2004 22:04:44 -0000
@@ -495,12 +495,14 @@ class EventHandler:
# search for events in the queue
- if len(self.queue):
- self.lock.acquire()
- ret = self.queue[0]
- del self.queue[0]
- self.lock.release()
- return ret
+ self.lock.acquire()
+ try:
+ if len(self.queue):
+ ret = self.queue[0]
+ del self.queue[0]
+ return ret
+ finally:
+ self.lock.release()
# search all input objects for new events
for i in self.inputs: