本文整理汇总了Python中messenger.Messenger.info方法的典型用法代码示例。如果您正苦于以下问题:Python Messenger.info方法的具体用法?Python Messenger.info怎么用?Python Messenger.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类messenger.Messenger
的用法示例。
在下文中一共展示了Messenger.info方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Alex
# 需要导入模块: from messenger import Messenger [as 别名]
# 或者: from messenger.Messenger import info [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
#.........这里部分代码省略.........
示例2: __getitem__
# 需要导入模块: from messenger import Messenger [as 别名]
# 或者: from messenger.Messenger import info [as 别名]
return
def __getitem__(self, name):
return self.get(name)
# example of how to use DataSvc
if __name__ == "__main__":
from messenger import Messenger
evt = DataSvc("evt")
msg = Messenger("msg")
evt.msg = msg
x = 10
y = [1, 2, 3]
z = {1: 1, 2: 2, 3: 3}
t = "text"
evt.put("x", x)
evt.put("y", y)
evt.put("z", z)
evt.put("t", t)
msg.info("x", evt["x"])
msg.info("y", evt["y"])
msg.info("z", evt["z"])
msg.info("t", evt["t"])