Closed corneyl closed 7 years ago
Wouldn't it be better to have just one thread sending? Like the keepalive thread waiting on a timeouting conditional that is notified by the send() if something was put into the queue?
That's also possible, but would it be really better? You continuously have to check the time to see whether the KEEP_ALIVE_TIME
has passed. Now the keep alive thread just sleeps most of the time. Code would probably be better readable, but would it differ performance-wise?
Well, you can still have multiple threads for timeout sending and whatever but you should do the self._socket.send(...)
either only from one thread or protect it with a lock, as a keepalive can happen at the same time as a command is send.
I can't test on v6, so whenever you guys are satisfied with the changes, let me know and I'll merge.
@happyleavesaoc Changes can be merged, tested for several days with this code and had no problems with permanent disconnects.
Can this be merged? Thanks!
Merged!
bridge.is_ready
could be changed from the keep-alive thread, while the consume thread was sending commands. As a result an exception was thrown atlimitlessled.group.commands.CommandV6.get_bytes()
with as result that the consume thread was stopped. This is solved by adding a threading lock tobridge.is_ready
.socket.error
catch is added to_send_raw()
to prevent daemon threads to stop.