Closed GwnDaan closed 2 years ago
Note that this issue only occurs when using multiple threads with all of them constantly (without sleeping) trying to read values from different i2c busses over the multiplexer.
Hm, @makermelissa and @tannewt this is interesting. This would imply that adafruit_bus_device
should change as well.
Ya, interesting. This is lightweight enough that I'd be ok with the change here and in bus device. This doesn't mean our drivers are threadsafe though. They are tested on micros without threads generally.
This request adds a sleep call of
0
seconds in the try_lock function. This resolves an issue where the current thread is constantly trying to lock the i2c bus, without giving another thread the 'opportunity' to complete it's operation and unlock the i2c bus.This sleep call drastically improves performance on my pi zero board: ^ without the sleep call
^ using the sleep call
I'm not sure if this is the right way of 'unblocking' the i2c bus for other threads, but it's for sure 1000x better than before for me. Therefore I feel like it's worth sharing with others.