コード例 #1
0
		def decorator(timer_function):
			"""This takes the timer's associated function as the only argument
			It defines the decorator and wrapper, as well as setting up the 'Timer' object and associating it with the decorated function.
			"""
			if 'name' not in t_kwargs: # No name for this timer was provided; use function name
				t_kwargs['name'] = timer_function.__name__
			# Create an instance of the 'Timer' class
			new_timer = Timer(self.scheduler, *t_args, **t_kwargs)  # provide a reffrence to the scheduler and all wrapper arguments to this instance
			def wrapper(*args, **kwargs):
				"""This function is what will be called in place of the decorated function;
				It takes the arguments given to it and passes them on to the provided function.
				"""
				r = timer_function(*args, **kwargs) # call the original trigger function
				return r
			new_timer.add_function(wrapper) # Associate the wrapper with the timer object
			# add the timer to an internal list
			self.timers.append(new_timer)
			return wrapper