summaryrefslogtreecommitdiff
path: root/Lib/sched.py
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2011-11-22 21:19:37 +0100
committerGiampaolo Rodola' <g.rodola@gmail.com>2011-11-22 21:19:37 +0100
commitf683700121a34e6301e50e681c20ca846db6b171 (patch)
tree089192adcd19ee4d00fcbb91221fd8c269f1d794 /Lib/sched.py
parent23b0b9252e91f2a1262cf83c51d4f4621d655095 (diff)
downloadcpython-git-f683700121a34e6301e50e681c20ca846db6b171.tar.gz
sort last committed name in alphabetical order
Diffstat (limited to 'Lib/sched.py')
-rw-r--r--Lib/sched.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/sched.py b/Lib/sched.py
index 6c01e6968a..3e41198c10 100644
--- a/Lib/sched.py
+++ b/Lib/sched.py
@@ -35,6 +35,9 @@ from collections import namedtuple
__all__ = ["scheduler"]
class Event(namedtuple('Event', 'time, priority, action, argument, kwargs')):
+ def __init__(self, *args, **kwargs):
+ super(Event, self).__init__(*args, **kwargs)
+ self._scheduled = False
def __eq__(s, o): return (s.time, s.priority) == (o.time, o.priority)
def __ne__(s, o): return (s.time, s.priority) != (o.time, o.priority)
def __lt__(s, o): return (s.time, s.priority) < (o.time, o.priority)
@@ -59,6 +62,7 @@ class scheduler:
"""
event = Event(time, priority, action, argument, kwargs)
+ event._scheduled = True
heapq.heappush(self._queue, event)
return event # The ID
@@ -81,6 +85,9 @@ class scheduler:
self._queue.remove(event)
heapq.heapify(self._queue)
+ def is_scheduled(self, event):
+ return event._scheduled
+
def empty(self):
"""Check whether the queue is empty."""
return not self._queue
@@ -122,6 +129,7 @@ class scheduler:
# Verify that the event was not removed or altered
# by another thread after we last looked at q[0].
if event is checked_event:
+ event._scheduled = False
action(*argument, **kwargs)
delayfunc(0) # Let other threads run
else: