I have been trying to implement a live data viewer (spectrometer) in a bokeh server. I have been somewhat successful, but now I’m running into problems, to the point I am not sure if bokeh is even the right path.
What has worked so far: I have a server with a few plots, and a periodic callback. I estimate the sensor readout time (lets say 50 ms) and make the loop time for the periodic callback slightly higher to account for some data processing (lets say 60 ms). This works nicely and I get a live view of my spectrum.
However: The problems come, when I try to implement callbacks for buttons etc. If I press a button, the callback only gets executed a couple seconds later. What I want is an immediate reaction (to freeze the current spectrum for example).
What I’ve tried: Increasing the loop time only had a minor effect. I tried threading similar to this post. I made a seperate thread to readout the data + save in a data structure. This worked for very slow readout times (eg. 1 s), but at fast readouts (50 ms) everything was way worse.
At this point I am not sure how to continue. I looked into asyncio. Maybe multiprocessing would be an option too. Maybe there is an even easier way. I’ve also looked into add_next_tick_callback, but I’m not sure if this ist the right path. Any advice would be appreciated.