def __init__(self,no_calls,period,out_cont=output_controler(0.1),name='call controler'): threading.Thread.__init__(self) self.no_calls=no_calls self.period=period self.logs=[] self.timer_event=threading.Event() self.stop_event=threading.Event() self.out_cont=out_cont self.out=out_cont.create_outvar() self.name=name
while not self.stop: if not self.controler.timer_event.isSet(): print '%s is waiting' %self.name self.controler.timer_event.wait() self.log.log_event() # print '%s calls' %self.name time.sleep((float(1)/self.freq)) def stop(self): self.stop=True if __name__ == "__main__": out_cont=output_controler(0.2) out_cont.start() controler1=call_controler(50,10,out_cont, 'CONT 1') controler1.start() c1=caller('caller_1',controler1,2) c1.start() c2=caller('caller_2',controler1,2.5) c2.start() controler2=call_controler(50,10,out_cont, 'CONT 2') controler2.start() c3=caller('caller_3',controler2,2)