def callback(self, cb, bot, event): """ do the actual callback with provided bot and event as arguments. """ if event.stop: logging.info("callbacks - event is stopped.") ; return event.calledfrom = cb.modname try: if event.status == "done": logging.debug("callback - event is done .. ignoring") return if event.chan and cb.plugname in event.chan.data.denyplug: logging.warn("%s denied in %s - %s" % (cb.modname, event.channel, event.auth)) return if cb.prereq: logging.debug('callbacks - executing in loop %s' % str(cb.prereq)) if not cb.prereq(bot, event): return if not cb.func: return if event.isremote(): logging.info('%s - executing REMOTE %s - %s' % (bot.name, getname(cb.func), event.cbtype)) elif event.cbtype == "TICK": logging.debug('LOCAL - %s - executing %s - %s' % (bot.name, getname(cb.func), event.cbtype)) else: logging.info('%s - executing %s - %s' % (bot.name, getname(cb.func), event.cbtype)) event.iscallback = True logging.debug("callback - %s - trail - %s" % (getname(cb.func), callstack(sys._getframe())[::-1])) #if not event.direct and cb.threaded and not bot.isgae: start_new_thread(cb.func, (bot, event)) if cb.threaded and not bot.isgae: start_new_thread(cb.func, (bot, event)) else: if bot.isgae or event.direct: cb.func(bot, event) else: from runner import callbackrunner callbackrunner.put(cb.modname, cb.func, bot, event) return True except Exception, ex: handle_exception()
def list(self): """ show all callbacks. """ result = [] for cmnd, callbacks in self.cbs.iteritems(): for cb in callbacks: result.append(getname(cb.func)) return result
def _loop(self): """ the threadloops loop. """ logging.warn('starting %s' % getname(self)) self.running = True nrempty = 0 while not self.stopped: try: (speed, data) = self.queue.get() except IndexError: if self.stopped: break time.sleep(0.1) continue if self.stopped: break if not data: break try: self.handle(*data) except Exception, ex: handle_exception() self.running = False logging.warn('stopping %s' % getname(self))
def _loop(self): """ the threadloops loop. """ logging.debug('starting %s' % getname(self)) self.running = True nrempty = 0 while not self.stopped: try: (speed, data) = self.queue.get() except (IndexError, Queue.Empty): if self.stopped: break continue if self.stopped: break if not data: break try: self.handle(*data) ; self.lastiter = time.time() except Exception, ex: handle_exception() time.sleep(0.01) self.nrtimes += 1 self.running = False logging.warn('stopping %s' % getname(self))
def callback(self, cb, bot, event): """ do the actual callback with provided bot and event as arguments. """ if event.stop: logging.info("callbacks - event is stopped.") return event.calledfrom = cb.modname try: if event.status == "done": logging.debug("callback - event is done .. ignoring") return if event.chan and cb.plugname in event.chan.data.denyplug: logging.warn("%s denied in %s - %s" % (cb.modname, event.channel, event.auth)) return if cb.prereq: logging.debug('callbacks - executing in loop %s' % str(cb.prereq)) if not cb.prereq(bot, event): return if not cb.func: return if event.isremote(): logging.info('%s - executing REMOTE %s - %s' % (bot.name, getname(cb.func), event.cbtype)) elif event.cbtype == "TICK": logging.debug('LOCAL - %s - executing %s - %s' % (bot.name, getname(cb.func), event.cbtype)) else: logging.info('%s - executing %s - %s' % (bot.name, getname(cb.func), event.cbtype)) event.iscallback = True logging.debug("callback - %s - trail - %s" % (getname(cb.func), callstack(sys._getframe())[::-1])) #if not event.direct and cb.threaded and not bot.isgae: start_new_thread(cb.func, (bot, event)) if cb.threaded and not bot.isgae: start_new_thread(cb.func, (bot, event)) else: if bot.isgae or event.direct: cb.func(bot, event) else: from runner import callbackrunner callbackrunner.put(cb.modname, cb.func, bot, event) return True except Exception, ex: handle_exception()
def _loop(self): """ runner loop. """ logging.debug('%s - starting threadloop' % self.name) self.running = True while not self.stopped: try: speed, data = self.queue.get() if self.stopped: break if not data: break self.nowrunning = getname(data[1]) self.handle(speed, data) except IndexError: time.sleep(0.1) ; continue except Exception, ex: handle_exception() #self.nowrunning = getname(data[1]) + "-done" self.running = False logging.debug('%s - stopping threadloop' % self.name)
def _loop(self): """ runner loop. """ logging.debug('%s - starting threadloop' % self.name) self.running = True while not self.stopped: try: data = self.queue.get() except Queue.Empty: time.sleep(0.1) continue if self.stopped: break if not data: break self.nowrunning = getname(data[1]) try: self.handle(*data) except Exception, ex: handle_exception() self.running = False logging.debug('%s - stopping threadloop' % self.name)
def _loop(self): """ runner loop. """ logging.debug('%s - starting threadloop' % self.name) self.running = True while not self.stopped: try: data = self.queue.get() except Queue.Empty: time.sleep(0.1) continue if self.stopped: break if not data: break self.nowrunning = getname(data[1]) try: self.handle(*data) except Exception, ex: handle_exception()
def _loop(self): """ the threadloops loop. """ logging.debug('starting %s' % getname(self)) self.running = True nrempty = 0 while not self.stopped: try: (speed, data) = self.queue.get() except (IndexError, Queue.Empty): if self.stopped: break continue if self.stopped: break if not data: break try: self.handle(*data) self.lastiter = time.time() except Exception, ex: handle_exception() time.sleep(0.01) self.nrtimes += 1
class ThreadLoop(object): """ implement startable/stoppable threads. """ def __init__(self, name="", queue=None, *args, **kwargs): self.name = name self.stopped = False self.running = False self.outs = [] try: self.queue = queue or Queue.PriorityQueue() except AttributeError: self.queue = queue or Queue.Queue() self.nowrunning = "none" self.lastiter = 0 self.nrtimes = 0 def _loop(self): """ the threadloops loop. """ logging.debug('starting %s' % getname(self)) self.running = True nrempty = 0 while not self.stopped: try: (speed, data) = self.queue.get() except (IndexError, Queue.Empty): if self.stopped: break continue if self.stopped: break if not data: break try: self.handle(*data) self.lastiter = time.time() except Exception, ex: handle_exception() time.sleep(0.01) self.nrtimes += 1 self.running = False logging.warn('stopping %s' % getname(self))
def callback(self, cb, bot, event): """ do the actual callback with provided bot and event as arguments. """ #if event.stop: logging.info("callbacks - event is stopped.") ; return if event.cbtype in bot.nocbs and not cb.force: logging.warn("%s in nocbs list, skipping" % event.cbtype) ; return event.calledfrom = cb.modname if not event.bonded: event.bind(bot) try: if event.status == "done": if not event.nolog: logging.debug("callback - event is done .. ignoring") stats.upitem("ignored") return if event.chan and cb.plugname in event.chan.data.denyplug: logging.warn("%s denied in %s - %s" % (cb.modname, event.channel, event.auth)) stats.upitem("denied") return if cb.prereq: if not event.nolog: logging.info('executing in loop %s' % str(cb.prereq)) if not cb.prereq(bot, event): return if not cb.func: return if event.isremote(): logging.info('%s - executing REMOTE %s - %s' % (bot.cfg.name, getname(cb.func), event.cbtype)) elif not event.nolog: logging.info('%s - executing %s - %s' % (bot.cfg.name, getname(cb.func), event.cbtype)) event.iscallback = True if not event.nolog: logging.debug("%s - %s - trail - %s" % (bot.cfg.name, getname(cb.func), callstack(sys._getframe())[::-1])) time.sleep(0.01) if cb.threaded: logging.info("PURE THREAD STARTED %s" % str(cb.func)) ; start_new_thread(cb.func, (bot, event)) else: display = "%s/%s/%s" % (cb.plugname, bot.cfg.name, event.nick or event.channel) if event.cbtype == "API": from runner import apirunner apirunner.put(event.speed or cb.speed, display, cb.func, bot, event) elif event.direct: cb.func(bot, event) elif not event.dolong: from runner import callbackrunner callbackrunner.put(event.speed or cb.speed, display, cb.func, bot, event) else: from runner import longrunner longrunner.put(event.speed or cb.speed, display, cb.func, bot, event) stats.upitem(event.cbtype) stats.upitem("nrcallbacks") return True except Exception, ex: handle_exception()
def callback(self, cb, bot, event): """ do the actual callback with provided bot and event as arguments. """ #if event.stop: logging.info("callbacks - event is stopped.") ; return if event.cbtype in bot.nocbs and not cb.force: logging.warn("%s in nocbs list, skipping" % event.cbtype) return event.calledfrom = cb.modname if not event.bonded: event.bind(bot) try: if event.status == "done": if not event.nolog: logging.debug("callback - event is done .. ignoring") stats.upitem("ignored") return if event.chan and cb.plugname in event.chan.data.denyplug: logging.warn("%s denied in %s - %s" % (cb.modname, event.channel, event.auth)) stats.upitem("denied") return if cb.prereq: if not event.nolog: logging.info('executing in loop %s' % str(cb.prereq)) if not cb.prereq(bot, event): return if not cb.func: return if event.isremote(): logging.info('%s - executing REMOTE %s - %s' % (bot.cfg.name, getname(cb.func), event.cbtype)) elif not event.nolog: logging.info('%s - executing %s - %s' % (bot.cfg.name, getname(cb.func), event.cbtype)) event.iscallback = True if not event.nolog: logging.debug("%s - %s - trail - %s" % (bot.cfg.name, getname( cb.func), callstack(sys._getframe())[::-1])) time.sleep(0.01) if cb.threaded: logging.info("PURE THREAD STARTED %s" % str(cb.func)) start_new_thread(cb.func, (bot, event)) else: display = "%s/%s/%s" % (cb.plugname, bot.cfg.name, event.nick or event.channel) if event.cbtype == "API": from runner import apirunner apirunner.put(event.speed or cb.speed, display, cb.func, bot, event) elif event.direct: cb.func(bot, event) elif not event.dolong: from runner import callbackrunner callbackrunner.put(event.speed or cb.speed, display, cb.func, bot, event) else: from runner import longrunner longrunner.put(event.speed or cb.speed, display, cb.func, bot, event) stats.upitem(event.cbtype) stats.upitem("nrcallbacks") return True except Exception, ex: handle_exception()