| Reference | Downloads | Github

PsychoPy, Threads and Cython


I am writing a steady state visual evoked potential (SSVEP) experiment that uses psychoPy to create flashing targets. My code includes three threads (the main thread runs the PsychoPy and two other threads run cython code). The problem is that the frames are dropped. But i cannot understand why? When i run the psychoPy code with a thread that runs only python code, the frames are not dropped. Thus, there is no GPU problem. Also, the cython code does not allocate too much memory to cause frames drop.
Does anyone have ideas why the frames drop and how can i fix it?


If you are using Python threads, then they are probably causing your experiment to pause whenever they are scheduled to run by the Python interpreter. This can cause the experiment thread / process to drop frames.

One way to get around this would be to change your code to use a separate process for your own threads vs the main PsychoPy experiment code. This could be done by using the multiprocessing module or by using subprocess.Popen.

In both cases the main idea would be to start a separate process or script at the start of your experiment and have the cython code run in that process. Use some form of IPC to communicate / pass data between your experiment script and your other process.

Without more information on how and when the cython code and your experiment need to exchange data it is hard to give a specific example.

With multiprocessing the problem is solved.
Thank u

1 Like