本文整理汇总了Python中sys.print_exception方法的典型用法代码示例。如果您正苦于以下问题:Python sys.print_exception方法的具体用法?Python sys.print_exception怎么用?Python sys.print_exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.print_exception方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_state
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def load_state(self):
"""Verify file and load PIN state from it"""
try:
# verify that the pin file is ok
_, data = self.load_aead(self.path+"/pin", self.secret)
# load pin object
data = json.loads(data.decode())
self.pin = unhexlify(data["pin"]) if data["pin"] is not None else None
self._pin_attempts_max = data["pin_attempts_max"]
self._pin_attempts_left = data["pin_attempts_left"]
except Exception as e:
self.wipe(self.path)
sys.print_exception(e)
raise CriticalErrorWipeImmediately(
"Something went terribly wrong!\nDevice is wiped!\n%s" % e
)
示例2: board_name
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def board_name(default):
"""Returns the boards name (if available)."""
try:
import board
try:
name = board.name
except AttributeError:
# There was a board.py file, but it didn't have an name attribute
# We also ignore this as an error
name = default
except ImportError:
# No board.py file on the pyboard - not an error
name = default
except BaseException as err:
print('Error encountered executing board.py')
import sys
sys.print_exception(err)
name = default
return repr(name)
示例3: load_sinks
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def load_sinks(self, config) :
if 'sinks' in config :
ret = {}
sink_configs = config['sinks']
for name, config in sink_configs.items() :
try :
sink_name = name + "_sink"
mod = __import__(sink_name, globals(), locals(), ['Sink'], 0)
ret[name] = mod.Sink(config)
print("loaded sink {}".format(name))
except Exception as e :
print("Error: failed to load sink {} with config {}. Error: {}".format(name, config, e))
sys.print_exception(e)
return ret
else :
return {}
示例4: log
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def log(self, message) :
try :
print("{} [{}] {}: {}".format(
message['datetime'],
message['level'],
message['name'],
message['message'])
)
except Exception as e :
print("Error printing message:")
sys.print_exception(e)
print("begin message ==>")
print(message['datetime'])
print(message['level'])
print(message['name'])
print(message['message'])
print("<=== end message")
示例5: run
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def run(self):
try:
print("Welcome to ush-{}. Type 'help' for help. ^D to exit".format(VERSION))
while True:
line = Ush.prompt().strip()
if line:
tokens = line.split()
cmd = tokens[0]
if cmd in self._handlers:
handler = self._handlers[cmd]
try:
handler.handle_command(tokens[1:])
except Exception as e:
sys.print_exception(e)
else:
print("Unknown command: {}".format(cmd))
except Exception as e:
print(e)
示例6: update
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def update(self):
if self.manager == None:
return await asyncio.sleep_ms(100)
if self.usb is None:
return await asyncio.sleep_ms(100)
if not platform.usb_connected():
return await asyncio.sleep_ms(100)
res = self.read_to_file()
# if we got a filename - line is ready
if res is not None:
# first send the host that we are processing data
self.usb.write(self.ACK)
# open again for reading and try to process content
try:
with open(self.path+"/data", "rb") as f:
await self.process_command(f)
# if we fail with host error - tell the host why we failed
except HostError as e:
self.respond(b"error: %s" % e)
sys.print_exception(e)
# for all other exceptions - send back generic message
except Exception as e:
self.respond(b"error: Unknown error")
sys.print_exception(e)
self.cleanup()
# wait a bit
await asyncio.sleep_ms(10)
示例7: handle_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def handle_exception(self, exception, next_fn):
"""
Handle exception, show proper error message
and return next function to call and await
"""
try:
raise exception
except CriticalErrorWipeImmediately as e:
# wipe all wallets
self.wallet_manager.wipe()
# show error
await self.gui.error("%s" % e)
# TODO: actual reboot here
return self.setup
# catch an expected error
except BaseError as e:
# show error
await self.gui.alert(e.NAME, "%s" % e)
# restart
return next_fn
# show trace for unexpected errors
except Exception as e:
print(e)
b = BytesIO()
sys.print_exception(e, b)
await self.gui.error("Something unexpected happened...\n\n%s" % b.getvalue().decode())
# restart
return next_fn
示例8: host_exception_handler
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def host_exception_handler(self, e):
try:
raise e
except HostError as ex:
msg = "%s" % ex
except:
b = BytesIO()
sys.print_exception(e, b)
msg = b.getvalue().decode()
res = await self.gui.error(msg, popup=True)
示例9: _handle_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def _handle_exception(loop, context):
print('Global handler')
sys.print_exception(context["exception"])
sys.exit() # Drastic - loop.stop() does not work when used this way
示例10: _handle_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def _handle_exception(loop, context):
print('Global handler')
sys.print_exception(context["exception"])
sys.exit()
示例11: set_global_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def set_global_exception():
def _handle_exception(loop, context):
import sys
sys.print_exception(context["exception"])
sys.exit()
loop = asyncio.get_event_loop()
loop.set_exception_handler(_handle_exception)
示例12: exc
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def exc(self, e, msg, *args):
self.log(ERROR, msg, *args)
sys.print_exception(e, _stream)
示例13: log
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def log(self, level, format_str, *args) :
if level in self._levels :
try :
message = self.create(level, format_str, *args)
except Exception :
print("WARNING: Error formatting log message. Log will be delivered unformatted.")
sys.print_exception(e)
message = (level, format_str, args)
for name, sink in self._sinks.items() :
self.do_log(sink, message)
示例14: do_log
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def do_log(self, sink, message) :
try :
sink.log(message)
except Exception as e :
sys.print_exception(e)
示例15: internal_server_error
# 需要导入模块: import sys [as 别名]
# 或者: from sys import print_exception [as 别名]
def internal_server_error(writer, e):
sys.print_exception(e)
error_message = "Internal Server Error: {}".format(e)
return (yield from Server.error(writer, 500, error_message, e))