diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-11-05 22:46:29 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-11-05 22:46:29 +0100 |
commit | 1af5c88d37b5bb6e79467bc9a0e1552c4397eacc (patch) | |
tree | 83c51de78cd2f211d0ed27159082902c993c8d08 /module/Scheduler.py | |
parent | scheduler loop fix (diff) | |
download | pyload-1af5c88d37b5bb6e79467bc9a0e1552c4397eacc.tar.xz |
new priority queue
Diffstat (limited to 'module/Scheduler.py')
-rw-r--r-- | module/Scheduler.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/module/Scheduler.py b/module/Scheduler.py index f3dfa379e..1b700fc78 100644 --- a/module/Scheduler.py +++ b/module/Scheduler.py @@ -17,8 +17,8 @@ @author: mkaay """ -from time import sleep, time -from Queue import PriorityQueue, Empty +from time import time +from heapq import heappop, heappush from threading import Thread class AlreadyCalled(Exception): @@ -69,8 +69,8 @@ class Scheduler(): def work(self): while True: try: - t, j = self.queue.get(False) - except Empty: + t, j = self.queue.get() + except IndexError: break else: if t <= time(): @@ -96,3 +96,16 @@ class Job(Thread): self.deferred.callback() else: self.deferred.callback(ret) + + +class PriorityQueue(): + """ a non blocking priority queue """ + def __init__(self): + self.queue = [] + + def put(self, element): + heappush(self.queue, element) + + def get(self): + """ raises IndexError when empty """ + return heappop(self.queue)
\ No newline at end of file |