本文整理汇总了Python中moat.times.now函数的典型用法代码示例。如果您正苦于以下问题:Python now函数的具体用法?Python now怎么用?Python now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了now函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _start
def _start(self):
reported = False
while True:
sleep(self.freq)
try:
self.time_start = now()
self.old_seen = self.seen.copy()
# log(DEBUG,"SCAN",self.path,"IN",self.bus)
self.bus.dir(path=self.path+('alarm',), proc=self._reporter, cached=False)
for id in self.old_seen:
simple_event("onewire","alarm","state",id, bus=self.bus.bus.name, path=self.path, id=id, state="off")
self.seen.remove(id)
except Exception as e:
self.last_error = e
if not reported:
reported = True
fix_exception(e)
process_failure(e)
self.time_len = now()-self.time_start
sleep(self.freq*10)
else:
reported = False
self.time_len = now()-self.time_start
for x in self.simul:
x[0] += 1
if x[0] >= x[1]:
x[0] = 0
self.bus.set(self.path+('simultaneous',x[2]),x[3])
开发者ID:smurfix,项目名称:MoaT,代码行数:28,代码来源:onewire.py
示例2: info
def info(self):
if self.running not in ("off","error"):
tm = unixdelta(self.next-now())
elif self.last is not None:
tm = unixdelta(now()-self.last)
else:
tm = "never"
return "%s %s" % (self.running,tm)
开发者ID:M-o-a-T,项目名称:moat,代码行数:8,代码来源:timeslot.py
示例3: time_int
def time_int(self):
if self.started_at is None:
return None
if not self.running.is_set():
delta = now() - self.started_at
elif self.job:
delta = self.started_at - now()
else:
delta = now() - self.started_at
return unixdelta(delta)
开发者ID:smurfix,项目名称:MoaT,代码行数:10,代码来源:monitor.py
示例4: time_name
def time_name(self):
if self.started_at is None:
return "never"
if not self.running.is_set():
delta = now() - self.started_at
elif self.job:
delta = self.started_at - now()
else:
delta = now() - self.started_at
delta = unixdelta(delta)
res = humandelta(delta)
return u"‹"+res+"›"
开发者ID:smurfix,项目名称:MoaT,代码行数:13,代码来源:monitor.py
示例5: exposed_cmd_list
def exposed_cmd_list(self,*args):
# don't call this 'exposed_list'!
c = get_collect(args, allow_collection=True)
try:
if c is None:
for m in all_collect(skip=False):
yield m.name,
elif isinstance(c,Collection):
if args[-1] == "*":
for n,m in c.items():
yield n,m
return
for n,m in c.items():
try:
m = m.info
except AttributeError:
m = m.name
else:
if callable(m):
m = m()
if isinstance(m,six.string_types):
m = m.split("\n")[0].strip()
if m is not None:
yield (n,m)
else:
yield n,
else:
for p,t in flatten((c,)):
if isinstance(t,datetime):
if TESTING:
if t.year != 2003:
t = "%s" % (humandelta(t-now(t.year != 2003)),)
else:
t = "%s (%s)" % (humandelta(t-now(t.year != 2003)),t)
ti = t.rfind('.')
if ti>0 and len(t)-ti > 3 and len(t)-ti<9: # limit to msec
t= t[:ti+3]+")"
# otherwise transmit the datetime as-is
elif not isinstance(t,(date,time,timedelta)):
t = six.text_type(t)
yield p,t
except Exception as e:
fix_exception(e)
yield "* ERROR *",repr(e)
process_failure(e)
开发者ID:smurfix,项目名称:MoaT,代码行数:48,代码来源:rpc.py
示例6: list
def list(self):
n = now()
yield super(OutTimer,self)
yield ("output",self.parent.name)
yield ("start", self.started)
yield ("end", self.end)
yield ("next value",self.val)
开发者ID:M-o-a-T,项目名称:moat,代码行数:7,代码来源:in_out.py
示例7: __init__
def __init__(self,parent,name, names=("off","on"), **k):
self.ctx = parent.ctx
self.start = now()
self.names = names
for a,b in k.items(): self.arg(a,b)
self.validate()
super(CommonPM,self).__init__(*name)
开发者ID:smurfix,项目名称:MoaT,代码行数:7,代码来源:pwm.py
示例8: _do_measure
def _do_measure(self):
log("monitor",TRACE,"Start run",self.name)
try:
self.running.clear()
self.started_at = now()
self._monitor()
if self.send_check_event:
simple_event(self.ectx, "monitor","checked",*self.name)
if self.new_value is not None:
self.last_value = self.value
self.value = self.new_value
if hasattr(self,"delta"):
if self.last_value is not None:
val = self.value-self.last_value
self._ectx.value_delta = val
if val >= 0 or self.delta == 0:
simple_event(self.ectx,"monitor","update",*self.name)
else:
simple_event(self.ectx,"monitor","update",*self.name)
except Exception as e:
fix_exception(e)
process_failure(e)
finally:
log("monitor",TRACE,"Stop run",self.name)
self.running.set()
self._schedule()
开发者ID:smurfix,项目名称:MoaT,代码行数:26,代码来源:monitor.py
示例9: _list
def _list(self, args=(), **kw):
c = get_collect(args, allow_collection=True)
res = []
if c is None:
for m in all_collect(skip=False):
res.append(( m.name,))
elif isinstance(c,Collection):
if args[-1] == "*":
for n,m in c.items():
res.append(( n,m ))
return
for n,m in c.items():
try:
m = m.info
except AttributeError:
m = m.name
else:
if callable(m):
m = m()
if isinstance(m,str):
m = m.split("\n")[0].strip()
if m is not None:
res.append(( n,m ))
else:
res.append(( n, ))
else:
q = Queue(3)
job = spawn(flatten,q,(c,))
job.link(lambda _:q.put(None))
for p,t in flatten((c,)):
if isinstance(t,datetime):
if moat.TESTING:
if t.year != 2003:
t = "%s" % (humandelta(t-now(t.year != 2003)),)
else:
t = "%s (%s)" % (humandelta(t-now(t.year != 2003)),t)
ti = t.rfind('.')
if ti>0 and len(t)-ti > 3 and len(t)-ti<9: # limit to msec
t= t[:ti+3]+")"
# otherwise transmit the datetime as-is
elif not isinstance(t,(date,time,timedelta)):
t = str(t)
res.append(( p,t ))
return res
开发者ID:smurfix,项目名称:MoaT,代码行数:47,代码来源:qbroker.py
示例10: read
def read(self):
"""Read an output, check range."""
res = self._read()
res = self.repr(res)
self.check(res)
self.last_time = now()
self.last_value = res
return res
开发者ID:M-o-a-T,项目名称:moat,代码行数:8,代码来源:in_out.py
示例11: weigth
def weigth(self, mod=False):
if self.value_tm is None:
return None
t = now()-self.value_tm
nt = unixdelta(t)
if nt == 0: ## called right after init'ing
return 0
else:
return 1-(1-self.p)**(nt/self.p_base)
开发者ID:M-o-a-T,项目名称:moat,代码行数:9,代码来源:avg.py
示例12: feed
def feed(self, value):
self.prev_value = self.value
if value is None:
value = self.value
if value is None:
return
self.value = value
self.value_tm = now()
self.total_samples += 1
self.avg = self._calc(True)
开发者ID:M-o-a-T,项目名称:moat,代码行数:10,代码来源:avg.py
示例13: delete
def delete(self,ctx=None):
if self.working:
raise StateChangeError(self,u"‹deleted›")
self.working = True
self.time = now()
try:
if self.value is not None:
simple_event("state","delete",*self.name, prev_value=self.value)
finally:
super(State,self).delete()
开发者ID:smurfix,项目名称:MoaT,代码行数:10,代码来源:state.py
示例14: __init__
def __init__(self,parent,name,force,soft=None):
self.ctx = parent.ctx
self.start = now()
self.force = force
self.soft = soft
self._lock = Semaphore()
try:
self.parent = parent.parent
except AttributeError:
pass
super(Waiter,self).__init__(name)
开发者ID:smurfix,项目名称:MoaT,代码行数:11,代码来源:wait.py
示例15: report
def report(self, verbose=False):
if self.name:
yield "WORK: "+self.name
if self.id:
yield "id: "+str(self.id)
yield "call count: "+str(self.call_count)
if self.last_call:
yield "last call: %s (%s)" % (humandelta(now()-self.last_call),self.last_call)
if self.last_args:
for a,b in self.last_args.items():
yield "last %s: %s" % (a,b)
开发者ID:M-o-a-T,项目名称:moat,代码行数:11,代码来源:worker.py
示例16: out_one
def out_one(c):
for p,t in flatten((c,)):
if isinstance(t,datetime):
if TESTING and t.year != 2003:
t = "%s" % (humandelta(t-now(t.year != 2003)),)
else:
t = "%s (%s)" % (humandelta(t-now(t.year != 2003)),t)
if TESTING:
lim = 3
else:
lim = 4
ti = t.rfind('.')
if ti>0 and len(t)-ti>lim and len(t)-ti<lim+6: # limit to msec
t = t[:ti+lim]+")"
elif isinstance(t,float):
ft=float("%.4f"%t)
if abs(ft-t)<0.00000001:
t=ft
print(p+u": "+six.text_type(t), file=self.ctx.out)
开发者ID:M-o-a-T,项目名称:moat,代码行数:20,代码来源:data.py
示例17: sleepUntil
def sleepUntil(force,delta):
from moat.times import unixdelta,now,sleep
if isinstance(delta,dt.datetime):
delta = delta - now()
if isinstance(delta,dt.timedelta):
delta = unixdelta(delta)
if delta < 0: # we're late
delta = 0 # but let's hope not too late
sleep(force,delta)
开发者ID:M-o-a-T,项目名称:moat,代码行数:11,代码来源:twist.py
示例18: list
def list(self):
yield super(Timeslot,self)
yield ("run",self.running)
if self.interval is not None:
yield ("interval"," ".join(str(x) for x in self.interval))
yield ("duration",self.duration)
if self.last is not None:
yield ("last",self.last)
if self.next is not None:
yield ("next",self.next)
if self.slotter is not None:
yield ("slot",(unixdelta(self.next-now()))/self.duration)
开发者ID:M-o-a-T,项目名称:moat,代码行数:12,代码来源:timeslot.py
示例19: event
def event(self,ctx,data):
d={}
for m,n in data.items():
try: n = n * self.faktor[m]
except KeyError: pass
try: n = n + self.offset[m]
except KeyError: pass
d[m]=n
simple_event("fs20","tx", *self.name, **d)
self.last = now()
self.last_data = data
开发者ID:smurfix,项目名称:MoaT,代码行数:12,代码来源:fs20tx.py
示例20: on_info_msg
def on_info_msg(self,msg):
if not self._direct and not TESTING and getattr(msg,'message_id','').startswith(base_mseq):
return # dup
typ = getattr(msg,'content_type','')
try:
codec = get_codec(typ)
data = codec.decode(msg.body)
except Exception as e:
data = { "raw": msg.body, "content_type": typ, "error": e }
self.last_recv = msg.__dict__
if 'timestamp' not in data:
data['timestamp'] = now()
simple_event(*(self.prefix+tuple(msg.routing_key.split('.')[self.strip:])), _direct=self._direct, **data)
开发者ID:M-o-a-T,项目名称:moat,代码行数:13,代码来源:amqp.py
注:本文中的moat.times.now函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论