当前位置: 首页>>代码示例>>Python>>正文


Python Messenger.warning方法代码示例

本文整理汇总了Python中messenger.Messenger.warning方法的典型用法代码示例。如果您正苦于以下问题:Python Messenger.warning方法的具体用法?Python Messenger.warning怎么用?Python Messenger.warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在messenger.Messenger的用法示例。


在下文中一共展示了Messenger.warning方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Alex

# 需要导入模块: from messenger import Messenger [as 别名]
# 或者: from messenger.Messenger import warning [as 别名]
class Alex():
    
    def __init__(self, name='alex', nevts=100, evtfreq=100):
        """ Alex class
        It is the main driver application
        It has a list of algorithms that runs in sequence for a given number of events 
        It has a dictionary of services to be set into each algorithm
        It has a dictionary with run information and event information (clean each event) to be set into in each alorithm
        """
        self.name = name # name of the application 
        self.ievt = 0 # current number of event processed
        self.nevts = nevts # number of events to run
        self.evtfreq = evtfreq # frequency to print event number in log
        self.counters = {}
        self.algs = [] # list of algorithms to run
        self.svcs = {} # dictionary with the services
        # primordial msg service
        self.msg = Messenger(name='msg') 
        self.addsvc(self.msg) # add msg service 
        # primordial request service (handle errrors, abort/end of job requets)
        self.req = RequestSvc(name='req',al=self) 
        self.addsvc(self.req) # add request service
        # event data service
        self.evt = DataSvc(name='evt')
        self.addsvc(self.evt) # add event data service
        self.exports = ['msg','req','evt'] # services to export to algorithms
        return 

    def _declare(self,obj):
        """ add services and stores to the object 
        """    
        if (not hasattr(obj,'imports')): return
        nsvcs = obj.imports
        if (not isinstance(nsvcs,list)):
            self.msg.error(self.name,' no list of importing svc ',nsvcs)
            return
        if (isinstance(obj,ISvc)):
            if (not 'msg' in nsvcs): nsvcs.append('msg')
        elif (isinstance(obj,IAlg)):
            for svc in self.exports:
                if (not svc in nsvcs): nsvcs.append(svc)
        #self.msg.info(self.name,' importing services to ', obj.name)
        for nsvc in nsvcs:
            if (not self.svcs.has_key(nsvc)):
                self.msg.error(self.name,' no service ',nsvc,' to import ')
            else:
                svc = self.svcs[nsvc]
                if (svc.name != obj.name): setattr(obj,svc.name,svc) 
        return 
    
    def addsvc(self,svc):
        """ add a service by its name.
        Each service hass access to the msg svc and run store
        """
        self.msg.cinfo(self.name,' adding service ',svc.name)
        self.svcs[svc.name] = svc
        setattr(self,svc.name,svc)
        self._declare(svc)
        return

    def addalg(self,alg):
        """ add an algorithm to the list of algorithms to run.
        Services are set into the algorithm.
        It has access to the run store and event store.
        """
        self.msg.cinfo(self.name,' algorithm to run ',alg.name)
        self.algs.append(alg)
        self._declare(alg)
        # decorate the objects underneath
        if (hasattr(alg,'algs')):
            map(self._declare,alg.algs)
        return

    def initialize(self):
        """ initilize the services and the algorithms
        """
        self.msg.cinfo(' initilize ')            
        svcs = self.svcs.values()
        map(self._declare, svcs)
        oks1 = map(lambda svc: svc.initialize(), svcs)
        if (len(self.algs) == 0):
            self.msg.warning(self.name,' No algorithms to run')
            return True
        for alg in self.algs: self.counters[alg.name] = 0
        oks2 = map(lambda alg: alg.initialize(), self.algs)
        return (isok(oks1) and isok(oks2))

    def execute(self):
        """ do the execute method over the list of algorithms
        """
        if (self.ievt%self.evtfreq==0): 
            self.msg.cinfo(' event ', self.ievt)
        self.evt.clear()
        if (len(self.algs)==0): 
            self.ievt += 1; return True
        oks = map(lambda alg: alg.execute(), self.algs)
        def count(alg,ok):
            if (ok): self.counters[alg.name]+=1
        map(count,self.algs,oks)
        self.ievt+=1
#.........这里部分代码省略.........
开发者ID:nextsw,项目名称:alex,代码行数:103,代码来源:alex.py


注:本文中的messenger.Messenger.warning方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。