[subterfugue-cvs-commits] CVS: subterfugue/tricks CallDelayTrick.py,NONE,1.1
Status: Alpha
Brought to you by:
mkc
From: Martin M. <mar...@us...> - 2003-04-12 23:39:34
|
Update of /cvsroot/subterfugue/subterfugue/tricks In directory sc8-pr-cvs1:/tmp/cvs-serv24414 Added Files: CallDelayTrick.py Log Message: simple trick: adds minimal delay between calls --- NEW FILE: CallDelayTrick.py --- # add minimal delay between calls # Copyright 2003 Martin Macok <mar...@un...> # Can be freely distributed and used under the terms of the GNU GPL. from Trick import Trick import sys import time class CallDelay(Trick): def usage(self): return """ Add minimal delay between calls. The 'delay' parameter is required (in seconds). """ def __init__(self, options): if options.has_key('delay'): self.delay = options['delay'] else: sys.exit("error: %s: option required\nusage:%s" % (self.__class__.__name__, self.usage())) self.last_time = -1 def callbefore(self, pid, call, args): now = int(time.time()) since = now - self.last_time if since < self.delay: time.sleep(self.delay - since) self.last_time = now |