Experiment hangs on win.flip() when using LabStreamingLayer?


I’m coding an experiment using the psychopy library, it’s a relatively basic experiment. Participants will either listen to their partner talk about a picture, or talk about a picture to their partner, each for 15s.
During the talking aspect a picture will be drawn on a second screen (partner on the other screen). Prior to that I have a screen that flashes up for 2s that simply says ‘Talk’ so they are aware of what they have to do for that block.

The problem I am having is that sometimes my code hangs at the first win.flip() to present the 2s instruction window. It does nothing for way longer than it should, but I can’t seem to replicate the error with any consistency. The nature of the experiment is that I run the same code on two machines, and the same error happened there so it feels like it’s soemthing with my code but I can’t seem to figure out what.

The code has a bunch of other stuff (sockets, triggers, labstreaminglayer) all necessary for the experiment aswell.

I’m running it on a windows 10 machine using psychopy 2023.1.2 and pyglet 1.4.11 is managing the window. I tried with glfw and pygame but they both gave me other errors so I didn’t bother since the code runs fine sometimes.

I’ve posted the code I use below upto the point where it hangs.

#create monitor/window
win_stim = visual.Window(
    size=(1919, 1079), fullscr=True, screen=1, 
    winType='pyglet', allowStencil=False,
    monitor='Lab', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True, 
win_stim.mouseVisible = False

win_rest = visual.Window(
    size=(1919, 1070), fullscr=True, screen=2, 
    winType='pyglet', allowStencil=False,
    monitor='Lab', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True, 
win_rest.mouseVisible = False

rest_screen1 = visual.TextStim(win=win_rest,
   font='Segoe UI',
   pos=(0, 0)
rest_screen2 = visual.TextStim(win=win_stim,
   font='Segoe UI',
   pos=(0, 0)

listen_screen = visual.TextStim(win=win_stim,
   font='Segoe UI',
   pos=(0, 0)
talk_screen = visual.TextStim(win=win_rest,
   font='Segoe UI',
   pos=(0, 0)

print('check labrecorder and enable streams')
input("Press Enter to continue...") 

n_run = int(input("enter run number, NOTE: First run is ZERO: \n"))

#wait for connection
# Connect to server
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("connecting to %s on %s " % (ip_address, port))

while True:
    td_date = datetime.datetime.now().strftime("%Y%m%d")
    msg_server = server.recv(1024).decode()
    if msg_server:
        t = time()
        con_time = ctime(t)    
        f = open('C:\\Users\\usr\\Desktop\\logs\\log_' + td_date + '.txt','a')  
        f.write('Server Connect Time ' +' ' + 'Run ' + str(n_run) + ' ' +con_time + "\n")
        print("run", n_run)
        #present stim
        for n in range(n_loops):
            f.write('Loop ' + str(n)+ ' ' + tm.strftime("%H:%M:%S",tm.localtime())+ "\n")
             timer = core.CountdownTimer(2)
             while timer.getTime() > 0:
                 print('post draw')
                 win_stim.flip() #HANGS HERE#
                 print('post flip')

If I kill the process (ctrl+c) it says that it’s stopped here:

File “exp1.py”, line 37
File “E:\usr\programs\envs\psychopy\lib\site-packages\psychopy\visual\window.py”, line 1168, in flip
File “E:\usr\programs\envs\psychopy\lib\site-packages\psychopy\visual\backends\pygletbackend.py”, line 376, in swapBuffers
File “E:\usr\programs\envs\psychopy\lib\site-packages\pyglet\window\win32_init_.py”, line 644, in dispatch_events
while _user32.PeekMessageW(byref(msg), 0, 0, 0, PM_REMOVE):

Really unsure on how to proceed to troubleshoot so any suggestions or solutions would be really appreciated.

EDIT+4hours later: After some trawling through the various docs I’m supposing that the issue is VBI blocking - for some reason the flipp() isn’t detecting the VBI? I guess the next question is why would this happen? Should vsync be on or off?

EDIT+17hours later: I tested the vsync on/off and with waitBlanking=False and didnt seem to change much so I went through everything in my code possible to isolate the issue and it seems like the issue is with using LSL - if I have LabRecorder (the lsl application) already started the code runs fine, however, if I turn it on during the part where it says input(‘press enter to continue’) it seems to hang at the first win.flip().

I managed to fix it (i think) by implementing a subprocess.popen to run LabRecorder from wtihin the script rather than open the .exe manually. I have a suspicion that running labrecorder manually was engaging the streams I had open which was outputting something in the terminal window I was using just before the win.flip() was being run causing it to hang (not exactly sure of the reason why it would hang there, but my workaround seems to have solved it)

I’m running into the same issue on a Windows 10 machine, but am not using LabRecorder. Would appreciate any other ideas re solutions.

Hi, sorry for the late reply - yes, if there’s any part of your code where you need to do an input to the terminal window, try and comment it out and see if that helps. For some reason I think that was the real issue with mine