touchosc2midi
touchosc2midi copied to clipboard
Excessive CPU when idle
When touchosc2midi starts it waits for a message before entering its processing loop. During this initial phase CPU usage is low (~1% on a Raspberry Pi 3B+). After this, when it is in its loop waiting for data CPU usage rises (~10% on a Raspberry Pi 3B+). This is without any OSC traffic, i.e. it is sitting idle waiting for incoming messages. This seems excessively high CPU usage for an idle state.
This seems to be caused by the tight loop in the main function. I don't see why this is required. I think the loop could use any length of sleep because the OSC handlers are running in their own thread, e.g.
while True:
time.sleep(0.1)
(Use of 100ms to allow prompt reaction to interrupt signal.) A neater way may be to use the Event handler from threading which allows waiting for an interrupt signal with long loop delays. (But the fix above is simplest to implement and probably sufficient, certainly as users have been living with this behaviour so far.)