문제

PyOSC very courteously handles all kinds of exceptions, but unfortunately makes it difficult to debug. How do I defeat this?

For instance, I have a coding bug, which it reports as:

OSCServer: NameError on request from localhost:50542: global name 'cell' is not defined

Normally in python, this would throw up an exception with a helpful trace. But in PyOSC, this is all I get.

How do I turn off PyOSC's exception handling?

UPDATE: After a month, this question received zero comments or answers. Guess there aren't that many people using Python, open sound control, and the PyOSC module. I finally answered my own question below.

도움이 되었습니까?

해결책

Okay, I figured it out. Since PyOSC is only lightly documented, the source code serves as the documentation.

Here is the code that traps exceptions:

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)

And here's is the simple way you turn trace on when you create the OSCServer instance:

import OSC

myoscserver = OSC.OSCServer( (host, port) )
myoscserver.print_tracebacks = True

This works for OSCClient as well:

myoscclient = OSC.OSCClient()
myoscclient.connect( (host, port) )
myoscclient.print_tracebacks = True

Hope that helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top