DONE = 1
ERROR = 2
-
class Task(object):
""" This class is to define a task, that is represented by an id,
an execution time 'timestamp' and an action 'callback """
.. note::
- This class is thread safe.
- All calls to C Extensions are made atomic by the GIL in the CPython implementation.
- heapq.heappush, heapq.heappop, and list access are therefore thread-safe """
+ This class is thread safe.
+ All calls to C Extensions are made atomic by the GIL in the CPython implementation.
+ heapq.heappush, heapq.heappop, and list access are therefore thread-safe.
+
+ """
def __init__(self):
super(HeapScheduler, self).__init__()
self._valid = set()
self._idgen = itertools.count(1)
+ @property
+ def pending(self):
+ """ Returns the list of pending task ids """
+ return self._valid
+
def schedule(self, task):
""" Add the task 'task' in the heap of the scheduler
"""
if task.id == None:
task.id = self._idgen.next()
+
entry = (task.timestamp, task.id, task)
self._valid.add(task.id)
heapq.heappush(self._queue, entry)