def start_loop_threads(self): for event in irc.loops.events: if irc.loops.has_subscribers(event): log.debug('started thread for loop {}'.format(event)) t = LoopThread(irc.loops.events[event], event, self) t.start() self.loop_threads.append(t)
def start(self): log.info('Mainloop started!') self.start_loop_threads() try: for line in self.recieve_line(): log.debug('<<' + line) self.parse_line(line) except KeyboardInterrupt: self.stop_loop_threads() self.disconnect('Interrupted') except ConnectionResetError: self.stop_loop_threads() log.critical('connection reset by peer')
def subscribe(event, func): l = subscriptions.setdefault(event, []) if not func in l: l.append(func) log.debug('{} subscribed to loop {}!'.format(func, event))
def fire(event, *args, **kwargs): for func in subscriptions.get(event, []): func(*args, **kwargs) log.debug('fired {} by loop {}!'.format(func, event))
def fire(event, *args, **kwargs): for func in subscriptions.get(event, []): log.debug("fired {} by event {}!".format(func, event)) func(*args, **kwargs)