happyleavesaoc / python-limitlessled

MIT License
33 stars 22 forks source link

Improvements on preventing exceptions on an unstable connection #18

Closed corneyl closed 7 years ago

corneyl commented 7 years ago
janLo commented 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?

corneyl commented 7 years ago

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?

janLo commented 7 years ago

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.

happyleavesaoc commented 7 years ago

I can't test on v6, so whenever you guys are satisfied with the changes, let me know and I'll merge.

corneyl commented 7 years ago

@happyleavesaoc Changes can be merged, tested for several days with this code and had no problems with permanent disconnects.

corneyl commented 7 years ago

Can this be merged? Thanks!

happyleavesaoc commented 7 years ago

Merged!

corneyl commented 7 years ago

Thanks! Made PR for it...