diff --git a/src/schedule.py b/src/schedule.py index 3b36a8a7a..f98fe445f 100644 --- a/src/schedule.py +++ b/src/schedule.py @@ -72,7 +72,7 @@ class Schedule(drivers.IrcDriver): def name(self): return 'Schedule' - def addEvent(self, f, t, name=None): + def addEvent(self, f, t, name=None, args=[], kwargs={}): """Schedules an event f to run at time t. name must be hashable and not an int. @@ -83,13 +83,13 @@ class Schedule(drivers.IrcDriver): assert name not in self.events, \ 'An event with the same name has already been scheduled.' self.events[name] = f - heapq.heappush(self.schedule, mytuple((t, name))) + heapq.heappush(self.schedule, mytuple((t, name, args, kwargs))) return name def removeEvent(self, name): """Removes the event with the given name from the schedule.""" f = self.events.pop(name) - self.schedule = [(t, n) for (t, n) in self.schedule if n != name] + self.schedule = [x for x in self.schedule if n != name] # We must heapify here because the heap property may not be preserved # by the above list comprehension. We could, conceivably, just mark # the elements of the heap as removed and ignore them when we heappop, @@ -123,11 +123,11 @@ class Schedule(drivers.IrcDriver): 'why do we continue to live?') time.sleep(1) # We're the only driver; let's pause to think. while self.schedule and self.schedule[0][0] < time.time(): - (t, name) = heapq.heappop(self.schedule) + (t, name, args, kwargs) = heapq.heappop(self.schedule) f = self.events[name] del self.events[name] try: - f() + f(*args, **kwargs) except Exception, e: log.exception('Uncaught exception in scheduled function:') diff --git a/src/version.py b/src/version.py index 391d5d8a0..63d2add1d 100644 --- a/src/version.py +++ b/src/version.py @@ -1,3 +1,3 @@ """stick the various versioning attributes in here, so we only have to change them once.""" -version = '0.83.4.1+limnoria (2012-04-04T13:13:39+0000)' +version = '0.83.4.1+limnoria (2012-04-04T13:55:08+0000)'