python-osc引发RuntimeError

时间:2019-03-05 08:05:06

标签: python osc

每当我使用python-osc遇到RuntimeError问题时,我都会遇到问题 更改调度程序映射。有两个python清单 下面。第一个是一个简单的OSC客户端,它传输三个 消息:/ ping / map-foo和/ foo。

第二个是响应这些消息的OSC服务器。原来 服务器仅响应/ ping和/ map-foo。收到/ map-foo 消息/ foo被添加到调度程序映射中。向/ foo添加映射 引发错误,如下所示。服务器继续运行,并且 尽管有错误,也会建立到/ foo的映射。如果客户 传输/ foo服务器响应预期。

这是对更大应用程序的一小部分。我可以定义为 我想提前很多静态OSC消息。但是我需要能够 在应用程序运行时动态添加它们。

Manjaro上的Python 3.7.2

# client code
# usage:  python client.py           --> transmits /ping
#         python client.py /whatever --> transmits /whatever
#
import sys
from pythonosc.udp_client import SimpleUDPClient

ip, port = "127.0.0.1", 5000

def send(message):
    print("Sending {}".format(message))
    client = SimpleUDPClient(ip, port)
    client.send_message(message, " ")

if __name__ == '__main__':
    argv = sys.argv
    if len(argv) == 1:
        send("/ping")
    else:
        send(argv[1])

# server code
#
from pythonosc.dispatcher import Dispatcher
from pythonosc.osc_server import ThreadingOSCUDPServer

ip, port = "127.0.0.1", 5000

dispatcher = Dispatcher()

def foo(*_):
    print("foo message received")

def ping(*_):
    print("ping message received")

def map_foo(*_):
    print("map-foo message received")
    dispatcher.map("/foo", foo)

dispatcher.map("/ping", ping)
dispatcher.map("/map-foo", map_foo)

server = ThreadingOSCUDPServer((ip, port), dispatcher)
print("Serving...")
server.serve_forever()

#
# Results, client and server running is seperate terminals
#

[sj@crow] python server.py
Serving...


[sj@crow]$ python client.py
server --> ping message received

[sj@crow]$ python client.py /foo
server --> <does not respond, /foo not currently mapped>

[sj@crow]$ python client.py /map-foo
server --> 
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 47064)
Traceback (most recent call last):
  File "/usr/lib/python3.7/socketserver.py", line 650, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.7/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.7/socketserver.py", line 720, in __init__
    self.handle()
  File "/usr/lib/python3.7/site-packages/pythonosc/osc_server.py", line 55, in handle
    self.server.dispatcher.call_handlers_for_packet(self.request[0], self.client_address)
le "/usr/lib/python3.7/site-packages/pythonosc/dispatcher.py", line 111, in call_handlers_for_packet
    for handler in handlers:
  File "/usr/lib/python3.7/site-packages/pythonosc/dispatcher.py", line 74, in handlers_for_address
    for addr, handlers in self._map.items():
RuntimeError: dictionary changed size during iteration
----------------------------------------

[sj@crow]$ python client.py /foo
server --> foo message received

0 个答案:

没有答案