Window.flip lags after long latency

Hello Everyone,
I am new here so I apologise if my topic’s formatting isn’t correct for some reason.
I am coding an experiment in which the stimuli are onscreen until the user makes a keyboard response and there is no set limit on how long they are allowed to wait. I am running into a problem where longer wait times (around 35 seconds) using psychopy.waitKeys() causes the window.flip() function to lag noticeably. It can take almost a full second for the window to refresh which seems to me to indicate that something is seriously amiss. When the wait times are short the win.flip() is faster.

Below I have an example of some code that produces the effect on my machine. As you can see the code is so straightforward there is no obvious reason lag of this kind should be occurring.

I noticed another person (anakhnikian) had a similar topic but they encountered the problem using the builder and no solution has been provided yet.

The computer I am running this on is a Surface Book 2:

  • Windows 10 Pro
  • i7-8650U CPU @ 1.90GHz
  • 16 GB of Ram
  • Running PsychoPy v 2020.1.3

Thank you in advance for any insights you can provide.

import psychopy.visual as psyvis
import psychopy.event as psyevent
import psychopy.core as psycore
import psychopy.gui as psygui

timer = psycore.Clock()

win = psyvis.Window(
    units = "pix",
    size = [400, 400], 
    fullscr = False,
    monitor = None,
    color = [1, 1, 1]
    )

txt = psyvis.TextStim(
        win = win,
        text = "wait for about 35 seconds when you see this text then press space",
        color = [-1,-1,-1],
        height = 40
        )

txt.draw()

win.flip()

keys = psyevent.waitKeys(keyList = ['space'])
print(timer.getTime())

win.flip()
print(timer.getTime())

keys = psyevent.waitKeys(keyList = ['space'])
print(timer.getTime())

win.close()
print(timer.getTime())

Unfortunately, I thought I had solved the issue, but apparently not.

My laptop contains two graphics cards:

    1. The integrated Intel UHD Graphics 620
    1. NVIDIA GeForce GTX 1060

Python/Psychopy was using the integrated card and not the NVIDIA gaming card. Switching my computer’s configuration so that Psychopy is set to use the NIVIDIA card has improved the lag somewhat, but it is still noticeable after long latencies.

I wish I knew what was going on.

Instructions for switching graphics card priority for those who might find it useful:
Go to the Windows 10 Control Panel, open NVIDIA Control Panel, and then select the “Progam Settings” tab. The drop down menu that appears shows the list of programs that are set to use the NVIDA card. You just have to select “Add”, and then find your various Python executables (.exe), add them to the list, and make sure they are set to use the NVIDIA card.