コード例 #1
0
ファイル: PluginDispatcher.py プロジェクト: scjudd/SuperBot2
    def run(self):
        pdwtLog.debug("Worker thread started.")
        while True:
            while self.produce==None or self.consume==None:
                pdwtLog.debug("Waiting on producer and consumer","P:"+str(self.produce), "C:"+str(self.consume))
                sleep(1)
                if self.produce and self.consume:
                    pdwtLog.debug("Producer and consumer set.","P:"+str(self.produce),"C:"+str(self.consume))

            func,args = self.produce()
            pdwtLog.debug("Produced",func,args)

            if not self.running:
                pdwtLog.note("Shutting down")
                return
            try:
                pdwtLog.debug("Calling",func,args)
                response = call(func,args)
    
                if response and self.consume:
                    if isinstance(response,GeneratorType):
                        pdwtLog.debug("Generator",response)
                        for r in response:
                            pdwtLog.debug("Yielded",r)
                            self.consume(r)
                        pdwtLog.debug("End of generator",response)
                    else:
                        pdwtLog.debug("Returning",response)
                        self.consume(response)
                else:
                    pdwtLog.debug("Not returning.",response)
            except Exception as e:
                pdwtLog.warning("Exception caught!",e)
コード例 #2
0
ファイル: Core.py プロジェクト: theepicsnail/SuperBot2
    def HandleEvent(self, event):
        log.dict(event,"HandleEvent")

        pm = self._PluginManager
        if not pm:
            log.warning("No plugin manager")
            return

        pd = self._PluginDispatcher
        if not pd:
            log.warning("No plugin dispatcher")
            return

        ro = self._ResponseObject
        if not ro:
            log.warning("no response object")
            pass

        matches = pm.GetMatchingFunctions(event)
        log.debug("Matched %i hook(s)." % len(matches))

        for inst, func, args, servs in matches:
            newEvent = dictJoin(event, dictJoin(args,
                {"self": inst, "response": ro}))
            log.debug("Services found for plugin:", servs)
            if servs:
                log.debug("Event before processing:", newEvent)

            servDict={}
            servDict["event"]=newEvent
            servDict["pm"]=self._PluginManager
            servDict["pd"]=self._PluginDispatcher
            servDict["ro"]=self._ResponseObject
            servDict["c"]=self._Connector
            servDict["core"]=self
            servDict["config"]=self._Config
            for servName in servs:
                serv = pm.GetService(servName)
                log.debug("Processing service",servName,serv)
                call(serv.onEvent,servDict)

            if servs:
                log.dict(newEvent,"Event after processing:")
            #issue 5 fix goes here
            newEvent.update(servDict)
            pd.Enqueue((func, newEvent))
コード例 #3
0
    def run(self):
        args = {}
        crashProtection=[0]*30
        while self.active:
            try:
                crashProtection=crashProtection[1:]+[time()]
                if crashProtection[-1]-crashProtection[0]<5:
                    pdLog.error("A static thread has returned 30 times in 5 seconds. Killing process.")
                    return 
                
                args.update({"response":self.connectorInfo[0]})
                pddtLog.dict(args,"Calling callback.",self.callback)
                response = call(self.callback,args)
                if response and self.connectorInfo[1]:
                    if isinstance(response, GeneratorType):
                        pddtLog.debug("Generator", response)
                        for r in response:
                            if not self.active:
                                pddtLog.debug("No longer active. Shutting down.")
                                self.Stop()
                                return 
                            pddtLog.debug("Yielded", r)
                            self.connectorInfo[1](r)
                        pddtLog.debug("End of generator", response)
                    else:
                        pddtLog.debug("Returning", response)
                        self.connectorInfo[1](response)
                elif response:
                    pddtLog.warning("No consumer to consume response",response)
                else:
                    pddtLog.debug("Didn't return")
            except:
                if not self.active:
                    pdLog.exception("No longer active. Shutting down.")
                    self.Stop()
                    return

                if self.recover:
                    pdLog.exception("Recovering",crashProtection[-1]-crashProtection[0])
                else:
                    pdLog.exception("Not recovering. Shuttind down.")
                    self.Stop()
                    return
            delayLeft = self.callback.delay
            endTime = delayLeft + time()
            while time() < endTime:
                delay = min(endTime-time(),1)
                pdLog.debug("Delaying",delay)
                sleep(delay)
                if not self.active:
                    self.Stop()
                    return
コード例 #4
0
    def run(self):
        pdwtLog.debug("Worker thread started.")
        while True:
            self.active = False
            while self.produce == None or self.consume == None:
                pdwtLog.debug("Waiting on producer and consumer",
                        "P:" + str(self.produce), "C:" + str(self.consume))
                sleep(1)
                if not self.running:
                    pdwtLog.debug("Shutting down")
                    return
                if self.produce and self.consume:
                    pdwtLog.debug("Producer and consumer set.",
                            "P:" + str(self.produce), "C:" + str(self.consume))
            func, args = self.produce()
            self.active = True

            pdwtLog.debug("Produced", func)
            pdwtLog.dict(args)

            if not self.running:
                pdwtLog.note("Shutting down")
                return
            try:
                pdwtLog.debug("Calling", func)
                pdwtLog.dict(args)
                response = call(func, args)

                if response and self.consume:
                    if isinstance(response, GeneratorType):
                        pdwtLog.debug("Generator", response)
                        for r in response:
                            pdwtLog.debug("Yielded", r)
                            self.consume(r)
                        pdwtLog.debug("End of generator", response)
                    else:
                        pdwtLog.debug("Returning", response)
                        self.consume(response)
                else:
                    pdwtLog.debug("Not returning.", response)
            except NameError,n:
                pdwtLog.exception("NameError while evaluating plugin!", n.message)
            except:
コード例 #5
0
    def run(self):
        pdwtLog.debug("Worker thread started.")
        while True:
            while self.produce == None or self.consume == None:
                pdwtLog.debug("Waiting on producer and consumer",
                              "P:" + str(self.produce),
                              "C:" + str(self.consume))
                sleep(1)
                if self.produce and self.consume:
                    pdwtLog.debug("Producer and consumer set.",
                                  "P:" + str(self.produce),
                                  "C:" + str(self.consume))

            func, args = self.produce()
            pdwtLog.debug("Produced", func, args)

            if not self.running:
                pdwtLog.note("Shutting down")
                return
            try:
                pdwtLog.debug("Calling", func, args)
                response = call(func, args)

                if response and self.consume:
                    if isinstance(response, GeneratorType):
                        pdwtLog.debug("Generator", response)
                        for r in response:
                            pdwtLog.debug("Yielded", r)
                            self.consume(r)
                        pdwtLog.debug("End of generator", response)
                    else:
                        pdwtLog.debug("Returning", response)
                        self.consume(response)
                else:
                    pdwtLog.debug("Not returning.", response)
            except Exception as e:
                pdwtLog.warning("Exception caught!", e)