psychopy.org | Reference | Downloads | Github

Experiment freezes due to thisExp.addData

I am using the builder interface for PsychoPy 3.1.2 on a Win 8.1 (Pro) OS.

I am trying to save a variable that is created within a routine using a code component to the datafile. The variable seems to be working as it controls when the routine ends. The experiment only freezes if I attempt to add this variable to the datafile. Within the ‘end routine’ box, I have tried using both:
thisExp.addData('clickSequence',clickSequence)

and

currentLoop.addData('clickSequence',clickSequence)

In both cases, I end up with the following error message:

Traceback (most recent call last):
File “C:\Users\Jen\Google Drive\Research\MemoryOnline - Copy\VS_Memory_Seq_Online - Copy_lastrun.py”, line 2347, in
thisExp.addData(‘clickSequence’,clickSequence)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\data\experiment.py”, line 216, in addData
value = copy.deepcopy(value)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 150, in deepcopy
y = copier(x, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 215, in _deepcopy_list
append(deepcopy(a, memo))
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 280, in _reconstruct
state = deepcopy(state, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 150, in deepcopy
y = copier(x, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 280, in _reconstruct
state = deepcopy(state, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 150, in deepcopy
y = copier(x, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 280, in _reconstruct
state = deepcopy(state, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 150, in deepcopy
y = copier(x, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 280, in _reconstruct
state = deepcopy(state, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 150, in deepcopy
y = copier(x, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 280, in _reconstruct
state = deepcopy(state, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 150, in deepcopy
y = copier(x, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 280, in _reconstruct
state = deepcopy(state, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 150, in deepcopy
y = copier(x, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 280, in _reconstruct
state = deepcopy(state, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 150, in deepcopy
y = copier(x, memo)
File “C:\Program Files (x86)\PsychoPy3\lib\copy.py”, line 240, in _deepcopy_dict

The experiment freezes and crashes. I have been unable to find other reports of this on the forum. I am also planning to use this experiment on Pavlovia so am trying to keep code as simple as possible as I am not very good at translating it to JS. For info, here is the rest of the code component:

Begin routine:

clickSequence=[]

Each frame:


for square in [Sq1_3,Sq2_3,Sq3_3,Sq4_3,Sq5_3,Sq6_3,Sq7_3,Sq8_3,Sq9_3,Sq10_3,Sq11_3,Sq12_3,Sq13_3,Sq14_3,Sq15_3,Sq16_3]:
    if mouse.isPressedIn(square):
        if clickSequence==[]:
            clickSequence.append(square)
        elif square!=clickSequence[-1]:
            clickSequence.append(square)


# all clicked?
if len(clickSequence) >= len(respSequence):
    continueRoutine = False

End Routine:

thisExp.addData('clickSequence',clickSequence)


#determine if all items recalled, order doesn't matter

if list(set(clickSequence))==list(set(respSequence)):
    correctCount=correctCount+1

Really long shot…

I suspect that the line clickSequence.append(square) does not append the names Sq1_3, Sq2_3 but something much more…what if after this line you add an extra one like print(square) and see what the output is.

If I am correct it will be a rather long output for each square. I think at the end psychopy straggles to save all this info in the csv file hence the crash.

But as I said that is a really long shot.

Hi Yiannis,

Thanks for the response - you are indeed correct!

This is what ‘square’ is:

ImageStim(class=<class ‘psychopy.visual.image.ImageStim’>, autoLog=True, color=array([1., 1., 1.]), colorSpace=‘rgb’, contrast=1.0, depth=-15.0, flipHoriz=False, flipVert=False, image=‘GridSquare.png’, interpolate=True, mask=None, maskParams=None, name=‘Sq16_3’, opacity=1.0, ori=0.0, pos=array([ 0.375, -0.65 ]), size=array([0.23645833, 0.41481481]), texRes=128, units=‘norm’, win=Window(…))

No wonder it is causing saving issues. So I guess I want to change the code so that it is only adding the square number to clickSequence - that helps a lot.

Jenny

1 Like

For anyone experiencing the same issue in the future, I added a line of code to extract only the part of the variable square that I wanted; clickedSquare = square.name. I also made some other amends and changed the component names from Sqx_3 as I really only wanted the numbers from the squares in my variable clickSequence. The resulting (and working) code is as follows:

Begin routine

squares=[RSq1,RSq2,RSq3,RSq4,RSq5,RSq6,RSq7,RSq8,RSq9,RSq10,RSq11,RSq12,RSq13,RSq14,RSq15,RSq16]
clickSequence=[]
clickedSquare =[]
clickedSquareNum =[]

Each frame

for square in [RSq1,RSq2,RSq3,RSq4,RSq5,RSq6,RSq7,RSq8,RSq9,RSq10,RSq11,RSq12,RSq13,RSq14,RSq15,RSq16]:
    if mouse.isPressedIn(square):
        #find out the square name
        clickedSquare = square.name
        #extract the number only from the square name
        clickedSquareNum = int(''.join(filter(str.isdigit, clickedSquare)))
        #avoid double-clicks and add to clickSequence
        if clickSequence==[]:
            clickSequence.append(clickedSquareNum)
        elif clickedSquareNum!=clickSequence[-1]:
            clickSequence.append(clickedSquareNum)

# all clicked?
if len(clickSequence) >= len(respSequence):
    continueRoutine = False
    event.clearEvents()    

End routine

thisExp.addData('clickSequence',clickSequence)


#add to datafile
thisExp.addData('clickSequence',clickSequence)


#determine if all items recalled, order doesn't matter

if list(set(clickSequence))==list(set(respSequence)):
    correctCount=correctCount+1
1 Like