【发布时间】:2018-09-04 14:30:05
【问题描述】:
我在 Deferred 中收到错误未处理的错误: 有人可以帮忙吗,如何处理?
@inlineCallbacks
def start(self):
# First we try Avahi, if it fails we fallback to Bluetooth because
# the receiver may be able to use only one of them
log.info("Trying to use this code with Avahi: %s", self.userdata)
key_data = yield threads.deferToThread(self.discovery.find_key, self.userdata)
if key_data and not self.stopped:
success = True
message = ""
returnValue((key_data, success, message))
if self.bt_code and not self.stopped:
# We try Bluetooth, if we have it
log.info("Trying to connect to %s with Bluetooth", self.bt_code)
self.bt = BluetoothReceive(self.bt_port)
msg_tuple = yield self.bt.find_key(self.bt_code, self.mac)
key_data, success, message = msg_tuple
if key_data:
# If we found the key
returnValue((key_data, success, message))
在行抛出错误
key_data = yield threads.deferToThread(self.discovery.find_key, self.userdata)
【问题讨论】:
-
函数可以引发异常(延迟可以触发失败)。你有什么问题?
-
你好@Jean-PaulCalderone 我收到一个错误“Deferred 中的未处理错误:”并且我的程序崩溃了。我想通过记录一条消息来优雅地处理它(“key_data not found”)而不是“延迟中的未处理错误”
标签: python python-3.x python-2.7 twisted