0

PyOSC はあらゆる種類の例外を非常に丁寧に処理しますが、残念ながらデバッグが困難です。これどうやって倒すの?

たとえば、コーディングのバグがあり、次のように報告されます。

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

通常、Python では、これは有用なトレースで例外をスローします。しかし、PyOSC ではこれだけです。

PyOSC の例外処理をオフにするにはどうすればよいですか?

更新: 1 か月後、この質問にはコメントも回答もありませんでした。Python、オープン サウンド コントロール、および PyOSC モジュールを使用している人はそれほど多くないと思います。私は最終的に以下の自分の質問に答えました。

4

1 に答える 1

0

わかりました。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

それが役立つことを願っています。

于 2014-05-20T22:49:15.883 に答える