def __call__(self, inputdict:dict): LOG.debug(" received dic:" + str(inputdict)) if not inputdict: LOG.error("No input") return None with self.__worklock: import random rand = random.randint(1, 999999) self.__event.clear() for channel, strcontent in inputdict.items(): LOG.debug("Board Receiving: " + channel + " " + str(strcontent)) self.__sendToChannel(channel, rand, strcontent) # ctime = now() while True: self.__event.wait(self.__timeout) if not self.__event.isSet(): LOG.error("Board: TIMEOUT") #emit error to parent #delete rand in msgqueue newerror = Error("Timeout") newerror.appendSource(self.ecuid.name) return newerror # if there is an error assoc to rand: # emit error to parent # delete rand in msgqueue # return {} error = self._queue.getErrorById(rand) if error != None: error.appendSource(self.ecuid.name) return error uidlist = [] for x in self.__outputGTDict.values(): uidlist.append(self._hostT[x[0]].ecuid) resultdic = self._queue.getResultsByMask(uidlist, rand) if not resultdic: self.__event.clear() continue else: break #result = self.__outputIOObject.getLog()[rand] #self.__outputIOObject.delLog(rand) #returns dict {outputchannelname:word,} uidlist = [] translationdic = {} #Extract all child identifiers for key, value in self.__outputGTDict.items(): uidlist.append(self._hostT[value[0]].ecuid) translationdic[value[0]] = (value[1], key) resultdic2 = {} #copia los valores #Translates output names for uid in uidlist: assert(len(resultdic[uid]) == 1) resultdic2[translationdic[uid.name][1]] = resultdic[uid][translationdic[uid.name][0]] return resultdic2
def __call__(self, ibdic): for inputkey in self.inputchanneldic.keys(): if inputkey not in ibdic: LOG.error("Key not found in inputdic") newerror = Error("Transformer") newerror.appendSource(self.ecuid) return newerror for dickey in ibdic.keys(): if not self.inputchanneldic[dickey].check(ibdic[dickey]): newerror = Error("Grammar") #FIXME: Should be Type error newerror.appendSource(self.ecuid) return newerror from pydsl.Exceptions import TProcessingError try: result = self._functionwrapper(ibdic) except TProcessingError: #TODO: Extract exception source newerror = Error("Transformer", [self.ecuid]) return newerror if isinstance(result, Error): result.appendSource(self.ecuid) return result if not result: newerror = Error("Transformer", [self.ecuid]) return newerror return result
def _functionwrapper(self, worddic): """Wraps function call, to add parammeters if required""" LOG.info("HostPythonTransformer._functionwrapper: begin") from pydsl.Exceptions import TProcessingError try: result = self._function(worddic, self._hostT, self.inputchanneldic, self.outputchanneldic, self._evfunctiondic) except TProcessingError: LOG.exception("__process: Index Error Exception calling function") newerror = Error("Tranformer") newerror.appendSource(self.ecuid.name) return newerror if isinstance(result, Error): result.appendSource(self.ecuid.name) return result for channel in result.keys(): if not result[channel]: #FIXME: > 1 channel receives an error newerror = result[channel] return newerror return result