kivy / oscpy

An efficient OSC implementation compatible with python2.7 and 3.5+
MIT License
109 stars 27 forks source link

Delay between close() and reopening a server #43

Open JPfeP opened 5 years ago

JPfeP commented 5 years ago

Hello,

I had a bug showing only when trying to reopen a server with the same IP (or changing from 0.0.0.0 to 127.0.0.1) and same port settings after a close() function.

The error message is that the port is already in use.

Traceback (most recent call last):
  File "/home/hebus/.config/blender/2.80/scripts/addons/MOM/osc.py", line 107, in save_osc_port_in
    bpy.ops.mom.refresh_osc()
  File "/Graphisme/blender-2.80-linux-glibc217-x86_64/2.80/scripts/modules/bpy/ops.py", line 201, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Error: Traceback (most recent call last):
  File "/home/hebus/.config/blender/2.80/scripts/addons/MOM/osc.py", line 140, in execute
    osc_server.listen(address=ip, port=port, default=True)
  File "/Graphisme/2.80_migration/MOM/oscpy/server.py", line 245, in listen
    sock.bind(addr)
OSError: [Errno 98] Address already in use

The solution I found was to introduce a delay using: time.sleep(.01)

10ms was the minimal value to avoid the issue.

tshirtman commented 5 years ago

Yes, i've add issues with that as well, tried adding a microsleep (with a much lower value than that), and the CI was still flacky, so for now i rely on retrying when that happens. But indeed it could be a good idea to make stop and stop_all do this directly. We can allow disabling it if people don't plan to reopen on the same port.