def main(self): global QUEUE QUEUE = TaskQueue(self.config) indexers = self.buildIndexers() for indexer in indexers: QUEUE.put(indexer) #start stat printing if self.statManager != None: timer = Timer() timer.scheduleAtFixedRate(StatLoggerTask(self.statManager, indexers), 0, self.config.statLoggingFrequency*60*1000) #start worker threads workers = [] for i in range(self.config.numThreads): t = Thread (target=ISWorker(self.config, self.statManager)) workers.append(t) t.setDaemon(1) t.start() for t in workers: t.join() log('Done!')
def registerExtenderCallbacks(self, callbacks): """ Burp initialisation function. Gets called when the extension is loaded and is in charge of building the UI. Args: callbacks: contains a burp callbacks object, as documented here https://portswigger.net/burp/extender/api/burp/IBurpCallbacks.html """ utility.setupLogging() utility.log("Loaded Benteveo Toolbox v0.2.2") state = State() # Endpoint table models are in charge of storing and disiplaying information in tables. state.endpointTableModel = EndpointTableModel(state, callbacks) state.requestTableModel = RequestTableModel(state, callbacks) state.replacementRuleTableModel = ReplacementRuleTableModel() # ToolboxUI handles building the Swing UI. ui = ToolboxUI() splitpane = ui.buildUi(state, callbacks) # Burp callbacks, to handle interactions with Burp. callbacks.addSuiteTab(Tab(splitpane)) callbacks.registerHttpListener(HttpListener(state, callbacks)) callbacks.setExtensionName("Benteveo Toolbox") callbacks.registerExtensionStateListener(ExtensionStateListener(state)) # Periodically check for new issues and report to slack. issueChecker = IssueChecker(state, callbacks) state.timer = Timer() state.timer.scheduleAtFixedRate(issueChecker, 1000, 1000)
def start(self): """Creates and starts a timer to perform the desired task as specified (in terms of timeInterval and repeat).""" if not self._running: # make sure we are not running already (otherwise, there is nothing to do) self._running = True # we are starting! (do this first) # create Timer (created here vs. __init()__ because of how stop() works - see below!) # and corresponding TimerTask (used in scheduling) self._timer = JTimer() self._timeListener = TimerTask(self, self._function, self._parameters) # and schedule it! if self._repeat: self._timer.scheduleAtFixedRate(self._timeListener, 0, self._timeInterval) else: self._timer.schedule(self._timeListener, self._timeInterval)
def startTimerTask(self): if self.timer: self.timer.cancel() self.timer = Timer() self.timer.schedule(BattleTask(), 100, 5000)
class MainFrame(java.lang.Runnable): def __init__(self): self.timer = None self.frame = None def run(self): frame = JFrame('MainFrame', defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE) self.addButtons(frame.getContentPane()) frame.size = (300, 175) frame.visible = 1 self.frame = frame self.startTimerTask() def startTimerTask(self): if self.timer: self.timer.cancel() self.timer = Timer() self.timer.schedule(BattleTask(), 100, 5000) def stopTimerTask(self): if self.timer: self.timer.cancel() def addButtons(self, container): pane = JPanel() pane.layout = BoxLayout(pane, BoxLayout.Y_AXIS) pane.add(JButton("Alliance", actionPerformed=self.clickAlliance)) pane.add(JButton("Enemy", actionPerformed=self.clickEnemy)) pane.add(JButton("None", actionPerformed=self.noMode)) pane.add(JButton("CheckPos", actionPerformed=self.checkPos)) pane.add(JButton("GetMousePos", actionPerformed=self.getCurrentPos)) pane.add(JButton("Exit", actionPerformed=self.stop)) container.add(pane) mode = 0 def clickAlliance(self, event): '''Click self hero or ...''' print('Click Alliance') global mode, check_teamviewer, check_battle check_teamviewer = kCountTeamviewer check_battle = kCountBattle mode = 2 def clickEnemy(self, event): '''Click enemy''' global mode, check_teamviewer, check_battle check_teamviewer = kCountTeamviewer check_battle = kCountBattle print('Click enemy') mode = 1 def noMode(self,event): global mode, check_teamviewer, check_battle check_teamviewer = 30 check_battle = 0 mode = 0 print('No mode') def checkPos(self,event): global mode mode = 0 mouseMove(check_pos) def getCurrentPos(self, event): global mode print('Start to Get mouse pos') mode = 4 Thread.sleep(3000) print('Get mouse pos') mouse_pos = Env.getMouseLocation() print('Current mouse pos: x:' + mouse_pos.x + ' y:' + mouse_pos.y) def stop(self, event): if self.timer: self.timer.cancel() self.frame.dispose() self.dispose() def __del__(self): if self.timer: self.timer.cancel() print('Deconstructor')
class Timer: """Timer used to schedule tasks to be run at fixed time intervals.""" def __init__(self, timeInterval, function, parameters=[], repeat=True): """Specify time interval (in milliseconds), which function to call when the time interval has passed and the parameters to pass this function, and whether to repeat (True) or do it only once.""" self._timeInterval = timeInterval self._function = function self._parameters = parameters self._repeat = repeat self._running = False # True when Timer is running, False otherwise self._timer = None # created in start(), exactly when needed self._timeListener = None # remember that this timer has been created and is active (so that it can be stopped/terminated by JEM, if desired) __ActiveTimers__.append(self) def setFunction(self, eventFunction, parameters=[]): """Sets the function to execute. The optional parameter parameters is a list of parameters to pass to the function (when called).""" self._timeListener.eventFunction = eventFunction self._timeListener.parameters = parameters def getRepeat(self): """Returns True if timer is set to repeat, False otherwise.""" return self._repeat def setRepeat(self, flag): """Timer is set to repeat if flag is True, and not to repeat if flag is False.""" self._repeat = flag # set the repeat flag self.start() # and start it (in case it had stopped) def getDelay(self): """Returns the delay time interval (in milliseconds).""" return self._timeInterval def setDelay(self, timeInterval): """Sets a new delay time interval for timer t (in milliseconds). This allows to change the speed of the animation, after some event occurs..""" self._timeInterval = timeInterval if self.isRunning(): # if running self.stop() # stop it, and self.start( ) # and re-start it (so that the new delay will take effect - no other way!) def _actionPerformed(self): if not self._repeat: self._timer.cancel() def isRunning(self): """Returns True if timer is still running, False otherwise.""" return self._running def start(self): """Creates and starts a timer to perform the desired task as specified (in terms of timeInterval and repeat).""" if not self._running: # make sure we are not running already (otherwise, there is nothing to do) self._running = True # we are starting! (do this first) # create Timer (created here vs. __init()__ because of how stop() works - see below!) # and corresponding TimerTask (used in scheduling) self._timer = JTimer() self._timeListener = TimerTask(self, self._function, self._parameters) # and schedule it! if self._repeat: self._timer.scheduleAtFixedRate(self._timeListener, 0, self._timeInterval) else: self._timer.schedule(self._timeListener, self._timeInterval) def stop(self): """Stops scheduled task from executing.""" if self._running: # make sure we are running (otherwise, there is nothing to do) # NOTE: The cancel() method terminates this timer, discarding any currently scheduled tasks. # Does not interfere with a currently executing task (if it exists). # Once a timer has been terminated, its execution thread terminates gracefully, and # no more tasks may be scheduled on it. That's why we create a new timer in start() above. self._timer.cancel() self._running = False # we are done running! (do this last)
from java.lang import Thread from java.util import Date from java.util import Timer from java.util import TimerTask class MyTask(TimerTask): def __init__(self, message): self.message = message def run(self): print Date(self.scheduledExecutionTime()), self.message # start a new timer 'daemon' my_timer = Timer(1) # add some tasks to the time queue start_time = Date() my_timer.schedule(MyTask("Python rules!"), start_time, 1000) my_timer.schedule(MyTask("... and Java too :)"), start_time, 3000) print "Start executing the tasks at", start_time Thread.currentThread().sleep(20000)
v['B'] += v2['B'] v['C'] += v2['C'] except: pass finally: f.close() except: pass print "votes:", v self.model.set(v['A'], v['B'], v['C']) if __name__ == "__main__": model = Model() if (len(argv) == 2): fsf = FullScreenFrame(int(argv[1])) else: fsf = FullScreenFrame() fsf.setup() model.add_observer(fsf) model.add_observer(fsf.votecounter_a) model.add_observer(fsf.votecounter_b) model.add_observer(fsf.votecounter_c) fsf.model = model fsf.set_game_rules(GameRulesAlpha(model)) twitter_task = TwitterTask(fsf) twitter_timer = Timer() twitter_timer.scheduleAtFixedRate(twitter_task, 5000, 5000) model.add_observer(fsf.winview)
class Timer: """Timer used to schedule tasks to be run at fixed time intervals.""" def __init__(self, timeInterval, function, parameters=[], repeat=True): """Specify time interval (in milliseconds), which function to call when the time interval has passed and the parameters to pass this function, and whether to repeat (True) or do it only once.""" self._timeInterval = timeInterval self._function = function self._parameters = parameters self._repeat = repeat self._running = False # True when Timer is running, False otherwise self._timer = None # created in start(), exactly when needed self._timeListener = None # remember that this timer has been created and is active (so that it can be stopped/terminated by JEM, if desired) __ActiveTimers__.append(self) def setFunction(self, eventFunction, parameters=[]): """Sets the function to execute. The optional parameter parameters is a list of parameters to pass to the function (when called).""" self._timeListener.eventFunction = eventFunction self._timeListener.parameters = parameters def getRepeat(self): """Returns True if timer is set to repeat, False otherwise.""" return self._repeat def setRepeat(self, flag): """Timer is set to repeat if flag is True, and not to repeat if flag is False.""" self._repeat = flag # set the repeat flag self.start() # and start it (in case it had stopped) def getDelay(self): """Returns the delay time interval (in milliseconds).""" return self._timeInterval def setDelay(self, timeInterval): """Sets a new delay time interval for timer t (in milliseconds). This allows to change the speed of the animation, after some event occurs..""" self._timeInterval = timeInterval if self.isRunning(): # if running self.stop() # stop it, and self.start() # and re-start it (so that the new delay will take effect - no other way!) def _actionPerformed(self): if not self._repeat: self._timer.cancel() def isRunning(self): """Returns True if timer is still running, False otherwise.""" return self._running def start(self): """Creates and starts a timer to perform the desired task as specified (in terms of timeInterval and repeat).""" if not self._running: # make sure we are not running already (otherwise, there is nothing to do) self._running = True # we are starting! (do this first) # create Timer (created here vs. __init()__ because of how stop() works - see below!) # and corresponding TimerTask (used in scheduling) self._timer = JTimer() self._timeListener = TimerTask(self, self._function, self._parameters) # and schedule it! if self._repeat: self._timer.scheduleAtFixedRate(self._timeListener, 0, self._timeInterval) else: self._timer.schedule(self._timeListener, self._timeInterval) def stop(self): """Stops scheduled task from executing.""" if self._running: # make sure we are running (otherwise, there is nothing to do) # NOTE: The cancel() method terminates this timer, discarding any currently scheduled tasks. # Does not interfere with a currently executing task (if it exists). # Once a timer has been terminated, its execution thread terminates gracefully, and # no more tasks may be scheduled on it. That's why we create a new timer in start() above. self._timer.cancel() self._running = False # we are done running! (do this last)