I currently have a working PsychoPy experiment that I am trying to integrate heart rate recordings into using Polar H10 sensors. I am using a Python package called bleakheart that streams data from the sensor using an asynchronous queue to record my ECG data. If you look at the ECG queue example on the github you will see what I have in mind. What I need to do is, using a single script, have this asynchronous data recording run in the background while my PsychoPy experiment proceeds, and have the two processes communicate with each other when needed.
For example, in the first part of the experiment I take a baseline ECG for five minutes. I’d like to either record ECG for just those five minutes or record throughout the experiment and drop triggers in the ECG data when the PsychoPy experiment starts and stops the relevant component.
In the main part of the experiment, I want to present stimuli in time with the R-waves. This also requires communication between the two processes, as the PsychoPy experiment needs to present a fixation cross, wait until the next R-wave is detected, and only then present the stimulus.
What is the best way to run this sort of asynchronous data streaming in the background while PsychoPy runs, while enabling communication between the two processes? I’ve seen some suggestions that threading might work and others suggesting extreme caution should be used when using threading with PsychoPy. Any advice on how to implement this kind of recording within a PsychoPy script would be extremely welcome. If you need to know further details please feel free to ask.