I am developing a Python script in which I am sampling data from a BLE device at a rate of about 50-200Hz. As of right now, I am doing this synchronously:
while True:
if time_now > time_before + (1/sample_rate):
do_stuff()
This works great, except for the fact that it is blocking the thread and other applications completely (if I want to combine with a Qt GUI, e.g.). What is the correct way to go about this issue?
- Can I easily implement a multithreading setup, where each "sampler" (while-loop) gets its own thread?
- Should I implement timer operations, and how do I make sure the script is not killed while waiting for a new sample?
My problem is similar to this, which, however, is for C#.