本文整理汇总了Python中moat.twist.fix_exception函数的典型用法代码示例。如果您正苦于以下问题:Python fix_exception函数的具体用法?Python fix_exception怎么用?Python fix_exception使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fix_exception函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, name, host,port, socket=None):
self.socket = socket
self.host = host
self.port = port
self.name = name
storage2 = getattr(self,"storage2",{})
assert (host,port) not in storage2, "already known host/port tuple"
super(NetCommonConnector,self).__init__()
storage2[(host,port)] = self
external = (self.socket is not None)
if self.socket is None:
try:
self._connect()
except Exception as ex:
fix_exception(ex)
if isinstance(ex,EnvironmentError) and ex.errno in (errno.ECONNREFUSED,errno.EHOSTDOWN,errno.EHOSTUNREACH,errno.ENETDOWN,errno.ENETUNREACH,errno.ETIMEDOUT):
ex.no_backtrace = True
try:
del storage2[(host,port)]
except KeyError:
pass
else:
super(NetCommonConnector,self).delete()
try:
self.not_up_event(error=ex)
except Exception as ex2:
fix_exception(ex2)
process_failure(ex2)
reraise(ex)
self.handshake(False)
else:
self.handshake(True)
self.start_job("job",self._reader)
示例2: _connect
def _connect(self):
e = None
for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except socket.error as err:
fix_exception(err)
if e is None:
e = err
s = None
continue
try:
s.connect(sa)
except socket.error as err:
fix_exception(err)
if e is None:
e = err
s.close()
s = None
continue
break
if s is None:
reraise(e)
self.socket = s
示例3: _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])
示例4: simple_statement
def simple_statement(self,args):
fn = self.lookup(args)
try:
fn.run(self.ctx)
except Exception as ex:
fix_exception(ex)
self.error(self,ex)
示例5: _watcher
def _watcher(self):
res = []
while True:
if self.scan or res:
try:
self.update_all()
except Exception as ex:
fix_exception(ex)
process_failure(ex)
resl = len(res)
while res:
q = res.pop()
q.set_exception(ex)
else:
resl = len(res)
while res:
q = res.pop()
q.set(None)
if TESTING:
if resl: d = 5
else: d = 30
else:
if resl: d = 10
else: d = 300
while True:
try:
q = self.watch_q.get(timeout=(None if not self.scan else d if not res else 0))
except Empty:
break
else:
res.append(q)
示例6: dataReceived
def dataReceived(self, data):
self._stop_timer()
data = self.dbuf+data
while True:
xi = len(data)+1
try: pi = data.index(b'\r')
except ValueError: pi = xi
try: ei = data.index(b'\n')
except ValueError: ei = xi
if pi==xi and ei==xi:
break
if pi < ei:
self.lbuf = data[:pi].decode('utf-8')
data = data[pi+1:]
else:
msg = data[:ei].decode('utf-8')
data = data[ei+1:]
if msg == "" and self.lbuf is not None:
msg = self.lbuf
self.lbuf = None
try:
self.lineReceived(msg)
except Exception as e:
log("fs20",ERROR,msg,e)
fix_exception(e)
process_failure(e)
self.dbuf = data
self._start_timer()
示例7: get
def get(self,key):
if not self.bus:
raise DisconnectedDeviceError(self.id)
if not isinstance(key,tuple):
key = Name(key)
p = self.path
if self.bus_id is not None:
p += (self.bus_id,)
p += key
msg = ATTRgetmsg(p)
msg.queue(self.bus)
try:
res = msg.result.get()
except Exception as ex:
fix_exception(ex)
self.go_down(ex)
raise
if isinstance(res,bytes):
res = res.decode('utf-8')
try:
res = int(res)
except (ValueError,TypeError):
try:
res = float(res)
except (ValueError,TypeError):
pass
return res
示例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()
示例9: do_timed_switch
def do_timed_switch(self):
self.timer = None
try:
self.do_switch()
except Exception as e:
fix_exception(e)
process_failure(e)
示例10: process
def process(self, event,**k):
super(OnEventExec,self).process(**k)
try:
self.fn(event)
except Exception as ex:
fix_exception(ex)
process_failure(ex)
示例11: recv
def recv(self,msg):
if msg.type is MT_MULTILINE:
for x in msg.msg:
if x == "":
continue
m = _num.match(x)
if m is None:
continue
mon = int(m.group(0))
self.data[mon]=x[m.end():]
recvs,self.queue.receivers = self.queue.receivers,[]
for r in recvs:
mid = getattr(r,"msgid",None)
if mid is None or mid in self.data:
log("wago",TRACE,"found monitor",r)
self.queue.receivers.append(r)
else:
try:
raise DroppedMonitor(mid)
except DroppedMonitor as ex:
fix_exception(ex)
res = r.error(ex)
if res is SEND_AGAIN:
log("wago",TRACE,"retry monitor",r)
self.queue.enqueue(r)
else:
log("wago",TRACE,"drop monitor",r)
assert res is None or res is False, "%s.error returned %s"%(repr(r),repr(res))
return MINE
if msg.type is MT_NAK or msg.type is MT_ERROR:
simple_event("wago","monitor","error", msg=msg.msg)
return MINE
return NOT_MINE
示例12: report
def report(self, verbose=False):
try:
yield u"END: "+six.text_type(Name(self.name[1:]))
except Exception as e:
fix_exception(e)
print("LOGGER CRASH 4", file=sys.stderr)
print_exception(e,file=sys.stderr)
yield "END: REPORT_ERROR: "+repr(self.name[1:])
示例13: sendMsg
def sendMsg(self,conn, typ,data, rlen=0):
# messages are not tagged, so process received messages in strict order
self.prio = PRIO_STANDARD
try:
conn.sendMsg(typ,data,rlen)
except Exception as ex:
fix_exception(ex)
self.error(ex)
示例14: _run
def _run(self,ctx,**k):
try:
super(TryStatement,self).run(ctx,**k)
except Exception as err:
fix_exception(err)
if self.catch_do:
self.catch_do.run(ctx(error_=err), **k)
else:
process_failure(err)
示例15: load_module
def load_module(*m):
md = dict()
mod = None
p = None
for d in ModuleDirs:
p = os.path.join(d,m[-1])+".py"
try:
c = compile(open(p,"r").read(), p, "exec",0,True)
except (OSError,IOError):
md = None
continue
else:
eval(c,md)
break
try:
if not md:
if TESTING:
if os.path.isdir("modules"):
p = "modules"
else:
p = os.path.join(os.pardir,"modules")
p = os.path.join(p,m[-1])+".py"
c = compile(open(p,"r").read(), p, "exec",0,True)
else:
from pkg_resources import resource_string
p = "moat.modules."+m[-1]+".py"
c = compile(resource_string("moat.modules", m[-1]+".py"), os.path.join('moat','modules',m[-1]+".py"), "exec",0,True)
eval(c,md)
mod = md["init"]
if callable(mod):
mod = mod(*m)
elif len(event) > 1:
raise RuntimeError("You cannot parameterize this module.")
if not hasattr(mod,"load"):
mod.load = md["load"]
mod.unload = md["unload"]
try:
mod.load()
except BaseException as e:
fix_exception(e)
try:
mod.unload()
except Exception:
reraise(e)
else:
reraise(e)
# do not use finally: here
else:
mod.path = p
except BaseException:
if mod is not None and hasattr(mod,"name") and mod.name in Modules:
del Modules[mod.name]
raise
return mod