Add support for arguments to addPeriodicEvent callbacks.

This commit is contained in:
Valentin Lorentz 2012-12-19 19:48:46 +01:00
parent 97b48abaa2
commit 30c56ae19f

View File

@ -109,11 +109,11 @@ class Schedule(drivers.IrcDriver):
f = self.removeEvent(name)
self.addEvent(f, t, name=name)
def addPeriodicEvent(self, f, t, name=None, now=True):
def addPeriodicEvent(self, f, t, name=None, now=True, args=[], kwargs={}):
"""Adds a periodic event that is called every t seconds."""
def wrapper():
try:
f()
f(*args, **kwargs)
finally:
# Even if it raises an exception, let's schedule it.
return self.addEvent(wrapper, time.time() + t, name)