本文整理汇总了Python中PyTango.Except类的典型用法代码示例。如果您正苦于以下问题:Python Except类的具体用法?Python Except怎么用?Python Except使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Except类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __exit__
def __exit__(self,etype,e,tb): #Type of exception, exception instance, traceback
if not e and not etype:
pass
else:
stack = traceback.format_tb(tb)
exstring = '\n'.join(stack)
if self.verbose:
print '-'*80
self.logger.warning('%s Exception Catched, Tracebacks (most recent call last): %s;\n%s'%(etype.__name__,str(e),exstring))
sys.stdout.flush(); sys.stderr.flush()
print '-'*80
if self.postmethod: self.postmethod(exstring)
if etype is DevFailed:
#for k,v in e[0].items():print k,':',v
if True: #not self.rethrow: #re_throw doesn't work!
#The exception is throw just as it was
err = e[0]
Except.throw_exception(err.reason,err.desc,err.origin)
#Except.throw_exception(e.args[0]['reason'],e.args[0]['desc'],e.args[0]['origin'])
else: #It doesn't work!!!
#ex=DevFailed(e[0]['reason'],e[0]['desc'],e[0]['origin'])
#Except.re_throw_exception(ex, '','','')
pass
else: #elif etype is Exception:
exstring = self.origin or len(exstring)<125 and exstring or stack[-1]
Except.throw_exception(etype.__name__,str(e),exstring)
示例2: read_Data
def read_Data(self, attr):
desc = "Data attribute is not foreseen for reading. It is used only "\
"as the communication channel for the continuous acquisitions."
Except.throw_exception("UnsupportedFeature",
desc,
"PoolExpChannelDevice.read_Data",
ErrSeverity.WARN)
示例3: wrapper
def wrapper(*args,**kwargs):
try:
#logger.debug('Trying %s'%fun.__name__)
result = fun(*args,**kwargs)
#sys.stdout.write('fun DONE!!!\n')
return result
except DevFailed, e:
exstring=getPreviousExceptions()
if verbose:
print '-'*80
#exstring = traceback.format_exc()
logger.warning('DevFailed Exception Catched: \n%s'%exstring)
try:
if showArgs: logger.info('%s(*args=%s, **kwargs=%s)'%(fun.__name__,args,kwargs))
except:pass
sys.stdout.flush(); sys.stderr.flush()
print '-'*80
if postmethod: postmethod(exstring)
err = e.args[0]
if rethrow:
#Except.re_throw_exception(e,'','',"%s(...)"%fun.__name__)
Except.throw_exception(err.reason, exstring, "%s(...)"%fun.__name__)
else:
#Except.throw_exception(err.reason,err.desc,err.origin)
logger.warning(str((err.reason,err.desc,err.origin)))
return default
示例4: read_Value
def read_Value(self, attr):
oned = self.oned
# TODO: decide if we force the controller developers to store the
# last acquired value in the controllers or we always will use
# cache. This is due to the fact that the clients (MS) read the value
# after the acquisition had finished.
use_cache = oned.is_in_operation() and not self.Force_HW_Read
# For the moment we just check if we recently receive ValueBuffer.
# event. In this case, we use cache and clean the flag
# so the cached value will be returned only at the first readout
# after the acquisition. This is a workaround for the count executed
# by the MacroServer e.g. step scans or ct which read the value after
# the acquisition.
if not use_cache and self._first_read_cache:
use_cache = True
self._first_read_cache = False
value = oned.get_value(cache=use_cache, propagate=0)
if value.error:
Except.throw_python_exception(*value.exc_info)
state = oned.get_state(cache=use_cache, propagate=0)
quality = None
if state == State.Moving:
quality = AttrQuality.ATTR_CHANGING
self.set_attribute(attr, value=value.value, quality=quality,
timestamp=value.timestamp, priority=0)
示例5: ReloadMacro
def ReloadMacro(self, macro_names):
"""ReloadMacro(list<string> macro_names):"""
try:
for macro_name in macro_names:
self.macro_server.reload_macro(macro_name)
except MacroServerException, mse:
Except.throw_exception(mse.type, mse.msg, "ReloadMacro")
示例6: _to_motor_write_positions
def _to_motor_write_positions(self, pos):
w_positions = []
for elem in self.motor_group.get_user_elements():
position = pos[elem]
if position.in_error():
Except.throw_python_exception(*position.exc_info)
w_positions.append(position.w_value)
return w_positions
示例7: ReloadMacroLib
def ReloadMacroLib(self, lib_names):
"""ReloadMacroLib(sequence<string> lib_names):
"""
try:
for lib_name in lib_names:
self.macro_server.reload_macro_lib(lib_name)
except MacroServerException, mse:
Except.throw_exception(mse.type, mse.msg, "ReloadMacroLib")
示例8: ExceptionWrapper
def ExceptionWrapper(fun,logger=exLogger,postmethod=None, showArgs=False,verbose=False,rethrow=False,default=None):
'''
Implementation of the popular Catched() decorator:
* it will execute your method within a a try/except
* it will print the traceback
* if :rethrow: is False it will return :default: in case of exception
Example:
@ExceptionWrapper
def funny():
print 'what?'
end
funny()
'''
def wrapper(*args,**kwargs):
try:
#logger.debug('Trying %s'%fun.__name__)
result = fun(*args,**kwargs)
#sys.stdout.write('fun DONE!!!\n')
return result
except DevFailed, e:
exstring=getPreviousExceptions()
if verbose:
print '-'*80
#exstring = traceback.format_exc()
logger.warning('DevFailed Exception Catched: \n%s'%exstring)
try:
if showArgs: logger.info('%s(*args=%s, **kwargs=%s)'%(fun.__name__,args,kwargs))
except:pass
sys.stdout.flush(); sys.stderr.flush()
print '-'*80
if postmethod: postmethod(exstring)
err = e.args[0]
if rethrow:
#Except.re_throw_exception(e,'','',"%s(...)"%fun.__name__)
Except.throw_exception(err.reason, exstring, "%s(...)"%fun.__name__)
else:
#Except.throw_exception(err.reason,err.desc,err.origin)
logger.warning(str((err.reason,err.desc,err.origin)))
return default
except Exception,e:
#exstring = traceback.format_exc()
exstring=getPreviousExceptions()
if verbose:
print '-'*80
logger.error('Python Exception catched: \n%s'%exstring)
try:
if showArgs: logger.info('%s(*args=%s, **kwargs=%s)'%(fun.__name__,args,kwargs))
except:pass
print '-'*80
if postmethod: postmethod(exstring)
if rethrow:
Except.throw_exception('Exception',exstring,"%s(...)"%fun.__name__)
else:
return default
示例9: _on_pseudo_counter_changed
def _on_pseudo_counter_changed(self, event_source, event_type,
event_value):
# during server startup and shutdown avoid processing element
# creation events
if SardanaServer.server_state != State.Running:
return
timestamp = time.time()
name = event_type.name.lower()
attr_name = name
# TODO: remove this condition when Data attribute will be substituted
# by ValueBuffer
if name == "valuebuffer":
attr_name = "data"
try:
attr = self.get_attribute_by_name(attr_name)
except DevFailed:
return
quality = AttrQuality.ATTR_VALID
priority = event_type.priority
value, w_value, error = None, None, None
if name == "state":
value = self.calculate_tango_state(event_value)
elif name == "status":
value = self.calculate_tango_status(event_value)
elif name == "valuebuffer":
value = self._encode_value_chunk(event_value)
self._first_read_cache = True
elif name == "value":
if isinstance(event_value, SardanaAttribute):
# first obtain the value - during this process it may
# enter into the error state, either when updating the elements
# values or when calculating the pseudo value
value = event_value.value
if event_value.error:
error = Except.to_dev_failed(*event_value.exc_info)
timestamp = event_value.timestamp
else:
value = event_value
state = self.pseudo_counter.get_state(propagate=0)
if state == State.Moving:
quality = AttrQuality.ATTR_CHANGING
else:
if isinstance(event_value, SardanaAttribute):
if event_value.error:
error = Except.to_dev_failed(*event_value.exc_info)
else:
value = event_value.value
timestamp = event_value.timestamp
self.set_attribute(attr, value=value, w_value=w_value,
timestamp=timestamp, quality=quality,
priority=priority, error=error, synch=False)
示例10: read_Value
def read_Value(self, attr):
twod = self.twod
use_cache = twod.is_in_operation() and not self.Force_HW_Read
value = twod.get_value(cache=use_cache, propagate=0)
if value.error:
Except.throw_python_exception(*value.exc_info)
state = twod.get_state(cache=use_cache, propagate=0)
quality = None
if state == State.Moving:
quality = AttrQuality.ATTR_CHANGING
self.set_attribute(attr, value=value.value, quality=quality,
timestamp=value.timestamp, priority=0)
示例11: read_DialPosition
def read_DialPosition(self, attr):
motor = self.motor
use_cache = motor.is_in_operation() and not self.Force_HW_Read
state = motor.get_state(cache=use_cache, propagate=0)
dial_position = motor.get_dial_position(cache=use_cache, propagate=0)
if dial_position.error:
Except.throw_python_exception(*dial_position.exc_info)
quality = None
if state == State.Moving:
quality = AttrQuality.ATTR_CHANGING
self.set_attribute(attr, value=dial_position.value, quality=quality,
priority=0, timestamp=dial_position.timestamp)
示例12: read_CurrentValue
def read_CurrentValue(self, attr):
zerod = self.zerod
#use_cache = ct.is_action_running() and not self.Force_HW_Read
use_cache = self.get_state() == State.Moving and not self.Force_HW_Read
value = zerod.get_current_value(cache=use_cache, propagate=0)
if value.error:
Except.throw_python_exception(*value.exc_info)
quality = None
state = zerod.get_state(cache=use_cache, propagate=0)
if state == State.Moving:
quality = AttrQuality.ATTR_CHANGING
self.set_attribute(attr, value=value.value, quality=quality,
priority=0, timestamp=value.timestamp)
示例13: writeHook
def writeHook(self, value):
self.__reviewMonitorDependencies()
formula = self._write
modified = self._replaceAttrs4Values(formula, self._writeAttrs)
solution = self._solve(value, modified)
self.debug("write with VALUE=%s, %r means %s" % (value, formula, solution))
if self.write_not_allowed is not None:
if value != solution:
PyTangoExcept.throw_exception("Write %s not allowed" % value,
self.write_not_allowed,
self.owner.name,
ErrSeverity.WARN)
self._lastWrite = solution
return solution
示例14: on_controller_changed
def on_controller_changed(self, event_src, event_type, event_value):
# during server startup and shutdown avoid processing element
# creation events
if SardanaServer.server_state != State.Running:
return
timestamp = time.time()
name = event_type.name.lower()
multi_attr = self.get_device_attr()
try:
attr = multi_attr.get_attr_by_name(name)
except DevFailed:
return
quality = AttrQuality.ATTR_VALID
priority = event_type.priority
error = None
if name == "state":
event_value = self.calculate_tango_state(event_value)
elif name == "status":
event_value = self.calculate_tango_status(event_value)
else:
if isinstance(event_value, SardanaAttribute):
if event_value.error:
error = Except.to_dev_failed(*event_value.exc_info)
timestamp = event_value.timestamp
event_value = event_value.value
self.set_attribute(
attr, value=event_value, timestamp=timestamp, quality=quality, priority=priority, error=error, synch=False
)
示例15: read_Position
def read_Position(self, attr):
# if motors are moving their position is already being updated with a
# high frequency so don't bother overloading and just get the cached
# values
motor_group = self.motor_group
use_cache = motor_group.is_in_operation() and not self.Force_HW_Read
position = motor_group.get_position(cache=use_cache, propagate=0)
if position.error:
Except.throw_python_exception(*position.exc_info)
state = motor_group.get_state(cache=use_cache, propagate=0)
quality = None
if state == State.Moving:
quality = AttrQuality.ATTR_CHANGING
self.set_attribute(attr, value=position.value, w_value=position.w_value,
quality=quality, priority=0,
timestamp=position.timestamp)