好吧,我想通了。由于 PyOSC 的文档很少,因此源代码用作文档。
这是捕获异常的代码:
def handle_error(self, request, client_address):
"""Handle an exception in the Server's callbacks gracefully.
Writes the error to sys.stderr and, if the error_prefix (see setSrvErrorPrefix()) is set,
sends the error-message as reply to the client
"""
(e_type, e) = sys.exc_info()[:2]
self.printErr("%s on request from %s: %s" % (e_type.__name__, getUrlStr(client_address), str(e)))
if self.print_tracebacks:
import traceback
traceback.print_exc() # XXX But this goes to stderr!
if len(self.error_prefix):
self.sendOSCerror("%s: %s" % (e_type.__name__, str(e)), client_address)
这是在创建 OSCServer 实例时打开跟踪的简单方法:
import OSC
myoscserver = OSC.OSCServer( (host, port) )
myoscserver.print_tracebacks = True
这也适用于 OSCClient:
myoscclient = OSC.OSCClient()
myoscclient.connect( (host, port) )
myoscclient.print_tracebacks = True
希望有帮助。