Python: Acessing each frame within a while loop
<p>In Psychopy/Python: within a while loop, I need to read in some information (using pyserial) and append it to a list on every frame. </p>

<pre><code>t = trialClock.getTime()
while True:

    line = ser.readline() #read in line
        if line:
        lines.append(line) #append to list

    ...
</code></pre>

<p>How can I access each frame using the trial clock? I need to read a line and append to the list every 0.016ms (60hz).</p>

<p>Thanks
Steve</p>

<p>You need to have a:</p>

<pre><code>win.flip()
</code></pre>

<p>at the end of your code within the while loop so that the loop only iterates once per frame refresh. i.e. the code pauses at that point until the screen is actually redrawn, limiting your loop to 60 Hz (assuming your screen refreshes at that rate).</p>

<p>That way, you are using very precise hardware timing, rather than using a software timer.</p>

python psychopy