OSC server timeout
CJRChang opened this issue · 3 comments
After starting an OSC server and idling, the listener times out due to recv on Python 2.7.
#Initialise OSC server
osc = OSCThreadServer()
sock = osc.listen(address='0.0.0.0', port=8000, default=True)
After a minute or so:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/rc/venv-python2-ros/local/lib/python2.7/site-packages/oscpy/server.py", line 257, in _listen
data, sender = sender_socket.recvfrom(65535)
timeout: timed out
A temporary workaround is to get the OSC server to poll itself, something along the lines of:
while not shutdownevent.isSet():
osc.send_message(b'/keepalive', [], '127.0.0.1', 8000)
time.sleep(2)
Perhaps using Select() (Python 2, Python 3) would be better.
Interestingly, select is used if the server is listening on more than one port/address, it just felt suboptimal for performances to do that in the more common case of just one.
Lines 264 to 267 in 507af64
maybe we should just do that all the time.
I wonder if it's worth creating a regression test for this bug, and if so, how to allow the test to run quickly (rather than actually wait for 15mn). Maybe i'll open an actual issue about it.