本文整理汇总了Python中traceback.format_tb函数的典型用法代码示例。如果您正苦于以下问题:Python format_tb函数的具体用法?Python format_tb怎么用?Python format_tb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format_tb函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __exit__
def __exit__(self, exc_type, exc_value, exc_tb):
self.end = time()
self.duration = self.end - self.start
if exc_type:
if issubclass(exc_type, SkipTest):
self.result = 'SKIP'
else:
if issubclass(exc_type, AssertionError):
self.result = 'FAIL'
self.traceback = ''.join(format_tb(exc_tb)[:-1])
else:
self.result = 'ERROR'
self.traceback = ''.join(format_tb(exc_tb))
self.error = '%s: %s' % (
exc_type.__name__, unicode(exc_value)
)
else:
self.result = 'OK'
if hasattr(self.testcase, 'test_actions'):
self.testcase.test_actions.append({
"text": self.text,
"start": self.start,
"end": self.end,
"duration": self.duration,
"result": self.result,
"error": self.error,
"traceback": self.traceback
})
if self.testcase.config.verbosity > 1:
msg = " ...%s\n" % self.result.lower()
print_debug(self.out, msg)
示例2: handle_exception
def handle_exception(self, exc_type, exc_value, exc_traceback):
# exceptions from blivet_utils have 'original' traceback as part of the message
# but we want to show the original message and traceback separately
exc_str, tr_str = self._parse_exception(exc_value)
if tr_str is not None:
tr_str += "------------------------------\n"
tr_str += "".join(traceback.format_tb(exc_traceback))
else:
tr_str = "".join(traceback.format_tb(exc_traceback))
allow_report = command_exists("gnome-abrt")
allow_ignore = self.allow_ignore and not issubclass(exc_type, errors.CommunicationError)
if allow_ignore:
msg = _("Unknown error occured.\n{error}").format(error=exc_str)
else:
msg = _("Unknown error occured. Blivet-gui will be terminated.\n{error}").format(error=exc_str)
dialog = message_dialogs.ExceptionDialog(self.main_window, allow_ignore,
allow_report, msg, tr_str)
response = dialog.run()
if response == constants.DialogResponseType.BACK:
return
else:
# restore handler and re-raise original exception
sys.excepthook = self.excepthook
sys.excepthook(exc_type, exc_value, exc_traceback)
if response == constants.DialogResponseType.REPORT:
subprocess.call(["gnome-abrt"])
Gtk.main_quit()
示例3: get_assemblies
def get_assemblies(self, job_id=None, asm_id=None, stdout=False, outdir=None):
if not job_id:
raise NotImplementedError('Job id required')
# Get node id
res = requests.get('http://{}/user/{}/job/{}/assembly'.format(
self.url, self.user, job_id), headers=self.headers)
# Download files
try:
nodes_map = json.loads(res.text)
if stdout: # Get first one and print
asm_file = self.shock.download_file(nodes_map.values()[0], outdir=outdir)
with open(asm_file) as f:
for line in f:
print line
elif asm_id:
ordered = collections.OrderedDict(sorted(nodes_map.items()))
id = ordered.values()[int(asm_id)-1]
self.shock.download_file(id , outdir=outdir)
else:
for node_id in nodes_map.values():
self.shock.download_file(node_id, outdir=outdir)
except:
print traceback.format_tb(sys.exc_info()[2])
print sys.exc_info()
raise Exception("Error retrieving results")
return
示例4: handle_pending_instances
def handle_pending_instances(self):
"""
method description.
recovery-controller I do the recovery
of outstanding recovery VM at startup.
"""
try:
self.rc_config.set_request_context()
db_engine = dbapi.get_engine(self.rc_config)
session = dbapi.get_session(db_engine)
self._update_old_records_vm_list(session)
result = self._find_reprocessing_records_vm_list(session)
# [recover_starter]section
recover_starter_dic = self.rc_config.get_value("recover_starter")
semaphore_multiplicity = recover_starter_dic.get(
"semaphore_multiplicity")
# Set multiplicity by semaphore_multiplicity
sem = threading.Semaphore(int(semaphore_multiplicity))
# Execute vm_recovery_worker
if len(result) > 0:
# Execute the required number
for row in result:
vm_uuid = row.uuid
primary_id = row.id
msg = "Run thread rc_worker.recovery_instance." \
+ " vm_uuid=" + vm_uuid \
+ " primary_id=" + str(primary_id)
LOG.info(msg)
thread_name = self.rc_util.make_thread_name(
VM_LIST, primary_id)
threading.Thread(
target=self.rc_worker.recovery_instance,
name=thread_name,
args=(vm_uuid, primary_id, sem)).start()
# Imperfect_recover
else:
return
return
except KeyError:
error_type, error_value, traceback_ = sys.exc_info()
tb_list = traceback.format_tb(traceback_)
LOG.error(error_type)
LOG.error(error_value)
for tb in tb_list:
LOG.error(tb)
return
except:
error_type, error_value, traceback_ = sys.exc_info()
tb_list = traceback.format_tb(traceback_)
LOG.error(error_type)
LOG.error(error_value)
for tb in tb_list:
LOG.error(tb)
return
示例5: create
def create(self, environ, start_response, route_vars):
"""POST /: Create new Inception Cloud."""
request_body = _read_request_body(environ)
opt_dict = anyjson.deserialize(request_body)
response_headers = [('Content-type', 'text/json')]
status = '200 OK'
result = {}
try:
# Copy request authorization environment to local environment
for kw in OS_AUTH_KEYWORDS:
os.environ[kw] = opt_dict[kw]
ao = OrchestratorThread(opt_dict, 'create')
ao.start()
result = {'cloud': {'id': ao.ic.id.hex, }}
except KeyError as ke:
# KeyError almost certainly means the OpenStack authorization
# environment (OS_*) wasn't provided making this a bad request
t, v, tb = sys.exc_info() # type, value, traceback
status = '400 Bad Request'
result = {'exception': {'type': t.__name__, 'value': v.args, }, }
except Exception:
t, v, tb = sys.exc_info() # type, value, traceback
print traceback.format_tb(tb)
status = '500 Internal Server Error'
result = {'exception': {'type': t.__name__, 'value': v.args, }, }
finally:
start_response(status, response_headers)
return [anyjson.serialize(result)]
示例6: _skip_node_accident_vm_recovery
def _skip_node_accident_vm_recovery(self, uuid, vm_state):
# Initalize status.
status = self.STATUS_NORMAL
try:
self.rc_util_api.do_instance_reset(uuid, 'error')
msg = "Skipped recovery. " \
"instance_id:%s, " \
"accident type: [node accident]." % (uuid)
LOG.info(self.rc_util.msg_with_thread_id(msg))
except EnvironmentError:
status = self.STATUS_ERROR
error_type, error_value, traceback_ = sys.exc_info()
tb_list = traceback.format_tb(traceback_)
LOG.error(self.rc_util.msg_with_thread_id(error_type))
LOG.error(self.rc_util.msg_with_thread_id(error_value))
for tb in tb_list:
LOG.error(self.rc_util.msg_with_thread_id(tb))
except:
status = self.STATUS_ERROR
error_type, error_value, traceback_ = sys.exc_info()
tb_list = traceback.format_tb(traceback_)
LOG.error(self.rc_util.msg_with_thread_id(error_type))
LOG.error(self.rc_util.msg_with_thread_id(error_value))
for tb in tb_list:
LOG.error(self.rc_util.msg_with_thread_id(tb))
return status
示例7: _marshaled_dispatch
def _marshaled_dispatch(self, data, dispatch_method=None):
logger.debug('data: "%s"' % data)
id = None
try:
req = json.loads(data)
method = req["method"]
params = req["params"]
id = req["id"]
if dispatch_method is not None:
result = dispatch_method(method, params)
else:
result = self._dispatch(method, params)
response = dict(id=id, result=result, error=None)
except:
extpe, exv, extrc = sys.exc_info()
err = dict(type=str(extpe), message=str(exv), traceback="".join(traceback.format_tb(extrc)))
response = dict(id=id, result=None, error=err)
logger.exception("Error while executing meth")
try:
return json.dumps(response)
except:
extpe, exv, extrc = sys.exc_info()
err = dict(type=str(extpe), message=str(exv), traceback="".join(traceback.format_tb(extrc)))
response = dict(id=id, result=None, error=err)
logger.exception("Error while marschalling")
return json.dumps(response)
示例8: GetUserNameById
def GetUserNameById(self, Id, case='nom'):
try:
if self.USERS.isCached(Id):
User = self.USERS.getCache(Id)
else:
try:
User = self.DefApi.users.get(user_ids=Id, v="5.60", fields=['sex'], name_case=case)[0]
self.USERS.cacheUser(Id,User)
except Exception as Ex:
exc_type, exc_value, exc_traceback = sys.exc_info()
TB = traceback.format_tb(exc_traceback)
print(TB,exc_type,exc_value)
User = None
except:
try:
User = self.DefApi.users.get(user_ids=Id, v="5.60", fields=['sex'], name_case=case)[0]
self.USERS.cacheUser(Id,User)
except Exception as Ex:
exc_type, exc_value, exc_traceback = sys.exc_info()
TB = traceback.format_tb(exc_traceback)
print(TB,exc_type,exc_value)
User = None
return User
示例9: execute_task
def execute_task(key, task_info, dumps, loads, get_id, raise_on_exception=False):
"""
Compute task and handle all administration
See Also
--------
_execute_task - actually execute task
"""
try:
task, data = loads(task_info)
result = _execute_task(task, data)
id = get_id()
result = dumps((result, None, id))
except Exception as e:
if raise_on_exception:
raise
exc_type, exc_value, exc_traceback = sys.exc_info()
tb = ''.join(traceback.format_tb(exc_traceback))
try:
result = dumps((e, tb, None))
except Exception as e:
if raise_on_exception:
raise
exc_type, exc_value, exc_traceback = sys.exc_info()
tb = ''.join(traceback.format_tb(exc_traceback))
result = dumps((e, tb, None))
return key, result
示例10: _marshaled_dispatch
def _marshaled_dispatch(self, data, dispatch_method = None):
id = None
try:
req = simplejson.loads(data)
method = req['method']
params = req['params']
id = req['id']
if dispatch_method is not None:
result = dispatch_method(method, params)
else:
result = self._dispatch(method, params)
response = dict(id=id, result=result, error=None)
except:
extpe, exv, extrc = sys.exc_info()
err = dict(type=str(extpe),
message=str(exv),
traceback=''.join(traceback.format_tb(extrc)))
response = dict(id=id, result=None, error=err)
try:
return simplejson.dumps(response)
except:
extpe, exv, extrc = sys.exc_info()
err = dict(type=str(extpe),
message=str(exv),
traceback=''.join(traceback.format_tb(extrc)))
response = dict(id=id, result=None, error=err)
return simplejson.dumps(response)
示例11: init
def init(self):
try:
if not seiscomp3.Client.Application.init(self): return False
try:
self.eventID = self.commandline().optionString("event")
except:
sys.stderr.write("An eventID is mandatory")
return False
try:
self.margin = self.commandline().optionInt("margin")
except: pass
try:
self.streams = self.commandline().optionString("streams").split(",")
except: pass
try:
self.allComponents = self.commandline().optionInt("all-components") != 0
except: pass
try:
self.allLocations = self.commandline().optionInt("all-locations") != 0
except: pass
return True
except:
cla, exc, trbk = sys.exc_info()
print cla.__name__
print exc.__dict__["args"]
print traceback.format_tb(trbk, 5)
示例12: _skip_process_accident_vm_recovery
def _skip_process_accident_vm_recovery(self, uuid, vm_state):
# Initalize status.
status = self.STATUS_NORMAL
try:
self.rc_util_api.do_instance_reset(uuid, 'error')
# Call nova stop API.
self.rc_util_api.do_instance_stop(uuid)
msg = ("Skipped recovery. instance_id:%s, "
"accident type: [qemu process accident]." % uuid)
LOG.info(msg)
except EnvironmentError:
status = self.STATUS_ERROR
error_type, error_value, traceback_ = sys.exc_info()
tb_list = traceback.format_tb(traceback_)
LOG.error(error_type)
LOG.error(error_value)
for tb in tb_list:
LOG.error(tb)
except:
status = self.STATUS_ERROR
error_type, error_value, traceback_ = sys.exc_info()
tb_list = traceback.format_tb(traceback_)
LOG.error(error_type)
LOG.error(error_value)
for tb in tb_list:
LOG.error(tb)
return status
示例13: displayTraceback
def displayTraceback(exception=None):
global log
import traceback
if exception is None:
tb = traceback.format_tb(sys.exc_info()[2])
else:
tb = traceback.format_tb(exception)
if log:
log("Traceback: " + str(sys.exc_info()[0].__name__) + ": " + str(sys.exc_info()[1]))
for line in tb:
if type(line) is tuple:
xline = ""
for item in line:
xline += str(item) + " "
line = xline
line = line.strip("\n")
if log:
log(line)
traceback.print_exc()
示例14: get_traceback
def get_traceback():
"""
If an exception has been caught, return the system stack trace or else
return stack trace of what is currently in the stack
"""
if traceback.format_tb(sys.exc_info()[2]):
delimiter = "\n"
traceback_pretty = "Traceback: \n%s" % \
delimiter.join(traceback.format_tb(sys.exc_info()[2]))
else:
# force traceback except for this call
stack = traceback.extract_stack()[:-1]
traceback_pretty = "%sForced traceback (most recent call last)" % \
(' ' * 4, )
for trace_tuple in stack:
traceback_pretty += """
File "%(file)s", line %(line)s, in %(function)s
%(text)s""" % {
'file': trace_tuple[0],
'line': trace_tuple[1],
'function': trace_tuple[2],
'text': trace_tuple[3] is not None and
str(trace_tuple[3]) or ""
}
return traceback_pretty
示例15: handle_read
def handle_read(self):
# debug
self.printd("handle_read")
try:
# read from my socket, printd it, and send to my peer
data = self.recv(4096)
except:
self.printd("EXCEPTION in recv: value=%s traceback=\n%s\n"
% (sys.exc_value, ''.join(format_tb(sys.exc_traceback))))
data = ""
else:
# debug
self.printd("handle_read: len(data)=%d" % (len(data),))
if len(data) == 0:
self.printd("CLOSED on read")
self.close()
# if I've already connected to the remote server, write immediately
if self.peer:
self.peer.write(data)
return
# try to parse a complete HTTP header
self.header_buf += data
hdr_match = http_header_re.match(self.header_buf)
if not hdr_match:
# not a complete header yet, keep reading
if len(self.header_buf) < self.header_max:
return
# error! too much data without an HTTP header. Barf!
self.close()
return
# debug
self.printd("handle_read: self.header_buf=[%s]" % (self.header_buf,))
try:
req = HttpReq()
self.request = req
# parse the HTTP header and find the remote server
headers = hdr_match.group(1);
(req.reqline, headers) = fixlen(2, re.split(r'\r?\n', headers, 1))
req.headers = HeaderParser().parsestr(headers)
(req.method, req.path, req.version) = fixlen(3, string.split(req.reqline, None, 3))
# debug
self.printd('req=%s' % (req,))
except:
# debug
self.printd("EXCEPTION in handle_read: value=%s traceback=\n%s\n"
% (sys.exc_value, ''.join(format_tb(sys.exc_traceback))))
# my parent can decide where to redirect this client to (by calling connect_server)
self.parent.handle_client(self)