summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-11-05 22:54:05 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-11-05 22:54:05 +0100
commit6820ab66f95371336dbe72df2efa679b609fed6d (patch)
tree19a8d9151f5dd1a2cf731cb28ee374a1d39f5ad3
parentnew priority queue (diff)
downloadpyload-6820ab66f95371336dbe72df2efa679b609fed6d.tar.xz
fixes
-rw-r--r--module/Scheduler.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/module/Scheduler.py b/module/Scheduler.py
index 1b700fc78..0032882fc 100644
--- a/module/Scheduler.py
+++ b/module/Scheduler.py
@@ -19,7 +19,7 @@
from time import time
from heapq import heappop, heappush
-from threading import Thread
+from threading import Thread, Lock
class AlreadyCalled(Exception):
pass
@@ -49,7 +49,7 @@ class Deferred():
raise AlreadyCalled
self.result = (args, kwargs)
for f, cargs, ckwargs in self.call:
- args.extend(cargs)
+ args+=tuple(cargs)
kwargs.update(ckwargs)
callInThread(f, *args, **kwargs)
@@ -102,10 +102,16 @@ class PriorityQueue():
""" a non blocking priority queue """
def __init__(self):
self.queue = []
+ self.lock = Lock()
def put(self, element):
+ self.lock.acquire()
heappush(self.queue, element)
+ self.lock.release()
def get(self):
""" raises IndexError when empty """
- return heappop(self.queue) \ No newline at end of file
+ self.lock.acquire()
+ el = heappop(self.queue)
+ self.lock.release()
+ return el \ No newline at end of file