Hello!
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,
units='height'
)
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,
units='height'
)
win_rest.mouseVisible = False
rest_screen1 = visual.TextStim(win=win_rest,
text='+',
font='Segoe UI',
pos=(0, 0)
)
rest_screen2 = visual.TextStim(win=win_stim,
text='+',
font='Segoe UI',
pos=(0, 0)
)
listen_screen = visual.TextStim(win=win_stim,
text='Listen',
font='Segoe UI',
pos=(0, 0)
)
talk_screen = visual.TextStim(win=win_rest,
text='Talk',
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)
#serverstuff
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:
server.close()
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")
task_start.write(5)
print("run", n_run)
#present stim
for n in range(n_loops):
print("loop",n,tm.strftime("%H:%M:%S",tm.localtime()))
f.write('Loop ' + str(n)+ ' ' + tm.strftime("%H:%M:%S",tm.localtime())+ "\n")
##TALK##
timer = core.CountdownTimer(2)
while timer.getTime() > 0:
print(timer.getTime())
talk_screen.draw()
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
win_stim.flip()
File “E:\usr\programs\envs\psychopy\lib\site-packages\psychopy\visual\window.py”, line 1168, in flip
self.backend.swapBuffers(flipThisFrame)
File “E:\usr\programs\envs\psychopy\lib\site-packages\psychopy\visual\backends\pygletbackend.py”, line 376, in swapBuffers
self.winHandle.dispatch_events()
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().