Eyelink II , exception in thread Thread-2

hi :wave:,
i need some help, I have a problem with my code
the goal is to play some videos and track eye’s motion at the same time.
(I am new in python and eyelink so maybe it’s a basic error I don’t know)

my code

###To set up connection with Eyelink II computer:
### ip link set enp4s0 up
### ip addr add 100.1.1.2/24 dev enp4s0

from __future__ import division 
import psychopy
from psychopy import visual, core, event
import time
import pylink as pl
import sys, os
import pygame
from pyglet.window import key
win = visual.Window(size=(800, 600))
keyState = key.KeyStateHandler()
win.winHandle.push_handlers(keyState)

print('win ok')

path = ''

globalClock = core.Clock()


def playvid(video):
    
    print('enter playvid')
    mov = visual.MovieStim(win, video)

    print('orig movie size=%s' % mov.size)
    print('duration=%.2fs' % mov.duration)

    start = globalClock.getTime()
    el.sendMessage("TRIALID " + str(subjname))
    el.startRecording(1, 1, 1, 1)

    print 'start recording'

    temps = globalClock.getTime() - start
    print temps
    while globalClock.getTime() - start <= mov.duration:
        temps = globalClock.getTime() - start
        print temps
        mov.draw()
        win.flip()  # modif
        if event.getKeys(keyList=['s']):
            print "exit loop"
            break
    print "end while"
    el.sendMessage("END")
    el.stopRecording()
    win.flip()
    print "videok"


def eyeTrkInit(sp):  # sp=size
    
    el = pl.EyeLink()
    print('initok')
    el.sendCommand("screen_pixel_coords = 0 0 %d %d" % sp)
    el.sendMessage("DISPLAY_COORDS  0 0 %d %d" % sp)
    el.sendCommand("select_parser_configuration 0")
    el.sendCommand("scene_camera_gazemap = NO")
    el.sendCommand("pupil_size_diameter = %s" % ("YES"))
    return (el)


def eyeTrkCalib(el, w, h, border, ntar, sp):  # cd=color dept
    
    print ('calibok')
    pl.openGraphics(sp, cd)
    print( el.eyeAvailable() ) # determine which eye(s) are available 1 RIGHT 0 LEFT

    el.sendCommand("button_function 5 'accept_target_fixation'");
    pl.setCalibrationColors((255, 255, 255), (0, 0, 0))
    pl.setTargetSize(int(sp[0] / 70), int(sp[1] / 300))
    pl.setCalibrationSounds("", "", "")
    pl.setDriftCorrectSounds("", "off", "off")
    el.doTrackerSetup()
    pl.closeGraphics()
    # # el.setOfflineMode()


def eyeTrkOpenEDF(dfn, el):

     el.openDataFile(dfn + '.EDF')


def eyeTrkCloseEDF(dfn, el):
    
     el.closeDataFile()


def driftCor(el, sp, cd):
    
      blockLabel = psychopy.visual.TextStim(win, text="Press the space bar to begin drift correction", pos=[0, 0], color="white", bold=True, alignHoriz="center", height=0.1)
    notdone = True
      while notdone:
        blockLabel.draw()
        win.flip()
        if keyState[key.SPACE] == True:
            eyeTrkCalib(el, w, h, border, ntar, sp)
            win.winHandle.activate()
            keyState[key.SPACE] = False
            notdone = False

    print ('fincal')
    

sp = (800, 600)
w = 800
h = 600
cd = 32
border = 100
ntar = 9

subjname = '060617'

el = eyeTrkInit(sp) #ini eyetrack

eyeTrkOpenEDF(subjname, el) #ouverture du fichier edf

eyeTrkCalib(el, w, h, border, ntar, sp) #calib

cpt = 0  # compteur drift
for f in ['Sample.mpg', 'small.mp4', 'jwpIntro.mov']: #boucle video

    pth = path + f
    print('debutvide')
    playvid(pth)
    cpt = cpt + 1
    print('finvide')
    if cpt < 2:
        driftCor(el, sp, cd)

el.setOfflineMode();

pl.closeGraphics()
eyeTrkCloseEDF(subjname, el)
edfFileName = subjname + ".EDF"
el.receiveDataFile(edfFileName, edfFileName)
el.close();
os.rename(edfFileName, subjname + '_mix.edf')

###error:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy2\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Program Files\PsychoPy2\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Program Files\PsychoPy2\lib\site-packages\pyglet\media\__init__.py", line 145, in _thread_run
    self.run()
  File "C:\Program Files\PsychoPy2\lib\site-packages\pyglet\media\drivers\directsound\__init__.py", line 61, in run for player in self.players:
RuntimeError: Set changed size during iteration

thanks for your helpp! :blush:
karine

Problem solved by using Moviestim2() instead of Moviestim()
simply download VLC player :slight_smile:

1 Like