program freezes at seemilgy random times

521 views
Skip to first unread message

susanne...@mail.mcgill.ca

unread,
Feb 4, 2014, 4:05:33 PM2/4/14
to psychop...@googlegroups.com
Dear all,

I created a program in psychopy that includes several routines in which e.g. pictures and rating scales are presented. In addition, I use this psychpy program  to control an external device for applying heat stimuli to the subject's skin. All works fine for a couple of trials but after around 5 trials the program freezes and can only be escaped by pressing alt + cmd + esc. The program not always freezes in the same trial or at the same time/routine. However, it seems to be somehow time dependent. That means if I speed up the program be answering the rating scales (two per trial) quickly instead of waiting for the maximum time allowed, the program runs through some more trials. For me it sounds possibly like a memory or buffer problem, but I have no idea where to look. In order to find the problem, I removed all parts from the program, which were in my opinion most likely causing this (i.e. some movies and an interval with quiet a lot of communication via the serial port). But unfortunately the problem persist. As I have no idea what might cause the freezing of the program, I copied the whole scripted compiled with the builder below. I'm using the builder in psychopy v1.78.01 on mac os x v10.6.8.

Any help would be highly appreciated as I'm stuck...
Susanne


#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy2 Experiment Builder (v1.78.01), Tue Feb  4 22:00:26 2014
If you publish work using this script please cite the relevant PsychoPy publications
  Peirce, JW (2007) PsychoPy - Psychophysics software in Python. Journal of Neuroscience Methods, 162(1-2), 8-13.
  Peirce, JW (2009) Generating stimuli for neuroscience using PsychoPy. Frontiers in Neuroinformatics, 2:10. doi: 10.3389/neuro.11.010.2008
"""

from __future__ import division  # so that 1/3=0.333 instead of 1/3=0
from psychopy import visual, core, data, event, logging, sound, gui
from psychopy.constants import *  # things like STARTED, FINISHED
import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions

# Store info about the experiment session
expName = u'WOWPainRelief_7woMovies'  # from the Builder filename that created this script
expInfo = {u'session': u'', u'participant': u''}
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False: core.quit()  # user pressed cancel
expInfo['date'] = data.getDateStr()  # add a simple timestamp
expInfo['expName'] = expName

# Setup files for saving
if not os.path.isdir('data'):
    os.makedirs('data')  # if this fails (e.g. permissions) we will get error
filename = 'data' + os.path.sep + '%s_%s' %(expInfo['participant'], expInfo['date'])
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING)  # this outputs to the screen, not a file

# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
    extraInfo=expInfo, runtimeInfo=None,
    originPath=None,
    savePickle=True, saveWideText=True,
    dataFileName=filename)

# Setup the Window
win = visual.Window(size=(1280, 800), fullscr=True, screen=0, allowGUI=True, allowStencil=False,
    monitor='testMonitor', color=[255,255,255], colorSpace='rgb')
# store frame rate of monitor if we can measure it successfully
expInfo['frameRate']=win._getActualFrameRate()
if expInfo['frameRate']!=None:
    frameDur = 1.0/round(expInfo['frameRate'])
else:
    frameDur = 1.0/60.0 # couldn't get a reliable measure so guess

# Initialize components for Routine "thermode_ini"
thermode_iniClock = core.Clock()
import serial
serPort = serialPort = serial.Serial('/dev/tty.PL2303-00001004', baudrate=9600, bytesize=8, parity='N',stopbits=1, timeout=0.0001, xonxoff = True)

# Thermode calibration presets assessed with the Cal4 program - UPDATE FOR CURRENT THERMODE!!!
# Thermode 25 x 50 - No. xxx
# *** DO NOT USE CAPS for hex values!!! ***
Gcal = 'G194'       # Offset DA temp - G 404 = 194
Hcal = 'H1bb'       # Scale  DA temp - H 44.3 = 1bb
Ocal = 'O003'       # Offset DA Slope- O 3 = 003
Ncal = 'N1ae'       # Scale  DA Slope- N 430 = 1ae
Kcal = 'K261'       # Offset AD temp - K 609 = 261
Lcal = 'L1c7'       # Scale  AD temp - L 45.5 = 1c7

#start settinggs Thermode
baselinetemp = 'B17c'
stimulustemp = 'T1cc' #46°C
stimulustemp_dec = 460  # = 46.0 * 100 for convertion to hex
rtc_stimulus = 'S05a'   # = 9deg/sec
rtc_baseline = 'R05a'   # = 9deg/sec

thermode_delay = 0.05         #Delay between sequential polling
thermal_stim_delay = 0.1    # Delay for fine-tuning the time course of thermal stimulus

# Thermode control codes
getT = 'M000'   #Get temperature from MSA
goB = 'C000'    # Goto baseline B with slope R
goT = 'C002'    # Goto stimulus T with slope S
goTB = 'C003'   # Goto stimulus T wait and return to baseline
getV1 = 'M006'  # Get VAS1 from MSA
get2 = 'M007'  # Get VAS2 from MSA
stimulustemp_dec = 460  # = 46.0 * 100 for convertion to hex
outcome_temp_win = 'T'+hex(stimulustemp_dec - 30)[2:]
outcome_temp_lose = 'T'+hex(stimulustemp_dec + 20)[2:]
up = 3
down = 3

start = visual.TextStim(win=win, ori=0, name='start',
    text=None,    font='Arial',
    pos=[0, 0], height=0.1, wrapWidth=None,
    color='black', colorSpace='rgb', opacity=1,
    depth=-1.0)

# Initialize components for Routine "trial"
trialClock = core.Clock()

wait = visual.TextStim(win=win, ori=0, name='wait',
    text='Bereit machen...',    font='Calibri',
    pos=[0, 0], height=0.3, wrapWidth=None,
    color='black', colorSpace='rgb', opacity=1,
    depth=-1.0)
memorize = visual.TextStim(win=win, ori=0, name='memorize',
    text='Jetzt Temperatur einpraegen',    font='Calibri',
    pos=[0, 0], height=0.1, wrapWidth=None,
    color='black', colorSpace='rgb', opacity=1,
    depth=-2.0)

chose = visual.TextStim(win=win, ori=0, name='chose',
    text='Farbe waehlen: pink <1> blau <2>',    font='Calibri',
    pos=[0,0.9], height=0.1, wrapWidth=None,
    color='black', colorSpace='rgb', opacity=1,
    depth=-4.0)
button_pink = visual.Rect(win=win, name='button_pink',
    width=[0.1, 0.15][0], height=[0.1, 0.15][1],
    ori=0, pos=[-0.2, -0.8],
    lineWidth=3, lineColor=[-1,-1,-1], lineColorSpace='rgb',
    fillColor='Fuchsia', fillColorSpace='rgb',
    opacity=1.0,interpolate=True)
button_blue = visual.Rect(win=win, name='button_blue',
    width=[0.1, 0.15][0], height=[0.1, 0.15][1],
    ori=0, pos=[0.2,-0.8],
    lineWidth=3, lineColor=[-1,-1,-1], lineColorSpace='rgb',
    fillColor='DodgerBlue', fillColorSpace='rgb',
    opacity=1.0,interpolate=True)
button_black = visual.Rect(win=win, name='button_black',
    width=[0.1, 0.15][0], height=[0.1, 0.15][1],
    ori=0, pos=[0, -0.8],
    lineWidth=1, lineColor='black', lineColorSpace='rgb',
    fillColor='black', fillColorSpace='rgb',
    opacity=1.0,interpolate=True)
image = visual.ImageStim(win=win, name='image',
    image='/Users/experiment/Documents/WOWPainRelief_newZI/WheelDisplay.JPG', mask=None,
    ori=0, pos=[0, 0], size=None,
    color=[1,1,1], colorSpace='rgb', opacity=1,
    texRes=128, interpolate=True, depth=-8.0)

showselection_pink = visual.Rect(win=win, name='showselection_pink',
    width=[0.1, 0.15][0], height=[0.1, 0.15][1],
    ori=0, pos=[-0.2, -0.8],
    lineWidth=10, lineColor='Gold', lineColorSpace='rgb',
    fillColor='Fuchsia', fillColorSpace='rgb',
    opacity=1.0,interpolate=True)
showselection_blue = visual.Rect(win=win, name='showselection_blue',
    width=[0.1, 0.15][0], height=[0.1, 0.15][1],
    ori=0, pos=[0.2, -0.8],
    lineWidth=10, lineColor='Gold', lineColorSpace='rgb',
    fillColor='DodgerBlue', fillColorSpace='rgb',
    opacity=1.0,interpolate=True)
showselection_black = visual.Rect(win=win, name='showselection_black',
    width=[0.1, 0.15][0], height=[0.1, 0.15][1],
    ori=0, pos=[0, -0.8],
    lineWidth=10, lineColor='Gold', lineColorSpace='rgb',
    fillColor='black', fillColorSpace='rgb',
    opacity=1.0,interpolate=True)

# Initialize components for Routine "outcome"
outcomeClock = core.Clock()

outcome_win = visual.TextStim(win=win, ori=0, name='outcome_win',
    text='Gewonnen!',    font='Calibri',
    pos=[0, 0], height=0.2, wrapWidth=None,
    color='black', colorSpace='rgb', opacity=1.0,
    depth=-1.0)
outcome_loss = visual.TextStim(win=win, ori=0, name='outcome_loss',
    text='Verloren!',    font='Calibri',
    pos=[0, 0], height=0.2, wrapWidth=None,
    color='black', colorSpace='rgb', opacity=1.0,
    depth=-2.0)
outcome_neut = visual.TextStim(win=win, ori=0, name='outcome_neut',
    text=None,    font='calibri',
    pos=[0, 0], height=0.1, wrapWidth=None,
    color='black', colorSpace='rgb', opacity=1.0,
    depth=-3.0)

# Initialize components for Routine "VAS_intensity_2"
VAS_intensity_2Clock = core.Clock()

VASIntensity = visual.RatingScale(win=win, name='VASIntensity', scale='Reizintensitaet',
low=0,
high=10,
showAnchors=True,
tickMarks=[0,5,10],
labels=['keine Empfindung', 'Schmerzschwelle','staerkster vorstellebarer Schmerz'],
precision =1,
showValue=False,
showAccept=False,
acceptKeys=['space'],
leftKeys=['1'],
rightKeys=['2'],
lineColor='black',
ticksAboveLine=False,
markerStyle='slider',
markerColor='DarkRed',
markerStart=5,
pos=(0,0),
stretchHoriz=2,
disappear=True)

# Initialize components for Routine "VAS_UnAngenehm"
VAS_UnAngenehmClock = core.Clock()

VASUnangenehm = visual.RatingScale(win=win, name='VASUnangenehm', scale='unangenehm/angenehm',
low=-5,
high=5,
showAnchors=True,
tickMarks=[-5,0,5],
labels=['extrem unangenehm', 'neutral','extrem angenehm'],
precision =1,
showValue=False,
showAccept=False,
acceptKeys=['space'],
leftKeys=['1'],
rightKeys=['2'],
lineColor='black',
ticksAboveLine=False,
markerStyle='slider',
markerColor='DarkRed',
markerStart=0,
pos=(0,0),
stretchHoriz=2,
disappear=True)

# Initialize components for Routine "end_trial"
end_trialClock = core.Clock()

end = visual.TextStim(win=win, ori=0, name='end',
    text='warten...\r\n',    font='Calibri',
    pos=[0, 0], height=0.1, wrapWidth=None,
    color='black', colorSpace='rgb', opacity=1,
    depth=-1.0)

# Create some handy timers
globalClock = core.Clock()  # to track the time since experiment started
routineTimer = core.CountdownTimer()  # to track time remaining of each (non-slip) routine

#------Prepare to start Routine "thermode_ini"-------
t = 0
thermode_iniClock.reset()  # clock
frameN = -1
routineTimer.add(0.500000)
# update component parameters for each repeat
serPort.write(Gcal)
print serPort.readline()
core.wait(thermode_delay)
serPort.write(Hcal)
core.wait(thermode_delay)
print serPort.readline()
serPort.write(Ocal)
core.wait(thermode_delay)
print serPort.readline()
serPort.write(Ncal)
core.wait(thermode_delay)
print serPort.readline()
serPort.write(Kcal)
core.wait(thermode_delay)
print serPort.readline()
serPort.write(Lcal)
print serPort.readline()
core.wait(thermode_delay)

serPort.write(baselinetemp)
print serPort.readline()
core.wait(thermode_delay)
serPort.write(stimulustemp)
print serPort.readline()
core.wait(thermode_delay)
serPort.write(rtc_stimulus)
print serPort.readline()
core.wait(thermode_delay)
serPort.write(rtc_baseline)
print serPort.readline()
core.wait(thermode_delay)

serPort.write(goB)
core.wait(thermode_delay)
print serPort.readline()
# keep track of which components have finished
thermode_iniComponents = []
thermode_iniComponents.append(start)
for thisComponent in thermode_iniComponents:
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED

#-------Start Routine "thermode_ini"-------
continueRoutine = True
while continueRoutine and routineTimer.getTime() > 0:
    # get current time
    t = thermode_iniClock.getTime()
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    lastCall = 0
    if t>(lastCall+1.5):
        serPort.write(getT)
        lastCall = t
   
    # *start* updates
    if t >= 0.0 and start.status == NOT_STARTED:
        # keep track of start time/frame for later
        start.tStart = t  # underestimates by a little under one frame
        start.frameNStart = frameN  # exact frame index
        start.setAutoDraw(True)
    elif start.status == STARTED and t >= (0.0 + 0.5):
        start.setAutoDraw(False)
   
    # check if all components have finished
    if not continueRoutine:  # a component has requested a forced-end of Routine
        routineTimer.reset()  # if we abort early the non-slip timer needs reset
        break
    continueRoutine = False  # will revert to True if at least one component still running
    for thisComponent in thermode_iniComponents:
        if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
            continueRoutine = True
            break  # at least one component has not yet finished
   
    # check for quit (the [Esc] key)
    if event.getKeys(["escape"]):
        core.quit()
   
    # refresh the screen
    if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
        win.flip()

#-------Ending Routine "thermode_ini"-------
for thisComponent in thermode_iniComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)

# set up handler to look after randomisation of conditions etc
trials = data.TrialHandler(nReps=24, method='sequential',
    extraInfo=expInfo, originPath=None,
    trialList=data.importConditions('trialorder.xlsx'),
    seed=None, name='trials')
thisExp.addLoop(trials)  # add the loop to the experiment
thisTrial = trials.trialList[0]  # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb=thisTrial.rgb)
if thisTrial != None:
    for paramName in thisTrial.keys():
        exec(paramName + '= thisTrial.' + paramName)

for thisTrial in trials:
    currentLoop = trials
    # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
    if thisTrial != None:
        for paramName in thisTrial.keys():
            exec(paramName + '= thisTrial.' + paramName)
   
    #------Prepare to start Routine "trial"-------
    t = 0
    trialClock.reset()  # clock
    frameN = -1
    routineTimer.add(3.500000)
    # update component parameters for each repeat
    serPort.write(getT)
    print serPort.readline()
    core.wait(thermal_stim_delay)
   
    serPort.write(goT)
    print serPort.readline()
   
    button_pink.setOpacity(0)
    button_blue.setOpacity(0)
    button_black.setOpacity(0)
    button_choice = event.BuilderKeyResponse()  # create an object of type KeyResponse
    button_choice.status = NOT_STARTED
   
    showselection_pink.setOpacity(0)
    showselection_blue.setOpacity(0)
    showselection_black.setOpacity(0)
    # keep track of which components have finished
    trialComponents = []
    trialComponents.append(wait)
    trialComponents.append(memorize)
    trialComponents.append(chose)
    trialComponents.append(button_pink)
    trialComponents.append(button_blue)
    trialComponents.append(button_black)
    trialComponents.append(image)
    trialComponents.append(button_choice)
    trialComponents.append(showselection_pink)
    trialComponents.append(showselection_blue)
    trialComponents.append(showselection_black)
    for thisComponent in trialComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
   
    #-------Start Routine "trial"-------
    continueRoutine = True
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = trialClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        lastCall = 0
        if t>(lastCall+1.0):
            serPort.write(getT)
            lastCall = t
       
        # *wait* updates
        if t >= 0.0 and wait.status == NOT_STARTED:
            # keep track of start time/frame for later
            wait.tStart = t  # underestimates by a little under one frame
            wait.frameNStart = frameN  # exact frame index
            wait.setAutoDraw(True)
        elif wait.status == STARTED and t >= (0.0 + 0.5):
            wait.setAutoDraw(False)
       
        # *memorize* updates
        if t >= 0.5 and memorize.status == NOT_STARTED:
            # keep track of start time/frame for later
            memorize.tStart = t  # underestimates by a little under one frame
            memorize.frameNStart = frameN  # exact frame index
            memorize.setAutoDraw(True)
        elif memorize.status == STARTED and t >= (0.5 + 0.5):
            memorize.setAutoDraw(False)
        if condition=='test':
            button_pink.setOpacity(1)
            button_blue.setOpacity(1)
        elif condition=='control':
            button_black.setOpacity(1)
       
        # *chose* updates
        if t >= 1 and chose.status == NOT_STARTED:
            # keep track of start time/frame for later
            chose.tStart = t  # underestimates by a little under one frame
            chose.frameNStart = frameN  # exact frame index
            chose.setAutoDraw(True)
        elif chose.status == STARTED and t >= (1 + 2.0):
            chose.setAutoDraw(False)
       
        # *button_pink* updates
        if t >= 1 and button_pink.status == NOT_STARTED:
            # keep track of start time/frame for later
            button_pink.tStart = t  # underestimates by a little under one frame
            button_pink.frameNStart = frameN  # exact frame index
            button_pink.setAutoDraw(True)
        elif button_pink.status == STARTED and t >= (1 + 2.0):
            button_pink.setAutoDraw(False)
       
        # *button_blue* updates
        if t >= 1 and button_blue.status == NOT_STARTED:
            # keep track of start time/frame for later
            button_blue.tStart = t  # underestimates by a little under one frame
            button_blue.frameNStart = frameN  # exact frame index
            button_blue.setAutoDraw(True)
        elif button_blue.status == STARTED and t >= (1 + 2.0):
            button_blue.setAutoDraw(False)
       
        # *button_black* updates
        if t >= 1 and button_black.status == NOT_STARTED:
            # keep track of start time/frame for later
            button_black.tStart = t  # underestimates by a little under one frame
            button_black.frameNStart = frameN  # exact frame index
            button_black.setAutoDraw(True)
        elif button_black.status == STARTED and t >= (1 + 2):
            button_black.setAutoDraw(False)
       
        # *image* updates
        if t >= 1 and image.status == NOT_STARTED:
            # keep track of start time/frame for later
            image.tStart = t  # underestimates by a little under one frame
            image.frameNStart = frameN  # exact frame index
            image.setAutoDraw(True)
        elif image.status == STARTED and t >= (1 + 2.5):
            image.setAutoDraw(False)
       
        # *button_choice* updates
        if t >= 1.0 and button_choice.status == NOT_STARTED:
            # keep track of start time/frame for later
            button_choice.tStart = t  # underestimates by a little under one frame
            button_choice.frameNStart = frameN  # exact frame index
            button_choice.status = STARTED
            # keyboard checking is just starting
            button_choice.clock.reset()  # now t=0
            event.clearEvents()
        elif button_choice.status == STARTED and t >= (1.0 + 2.0):
            button_choice.status = STOPPED
        if button_choice.status == STARTED:
            theseKeys = event.getKeys(keyList=['1', '2', '3'])
            if len(theseKeys) > 0:  # at least one key was pressed
                button_choice.keys = theseKeys[-1]  # just the last key pressed
                button_choice.rt = button_choice.clock.getTime()
        if button_choice.keys=='1': showselection_pink.setOpacity(1)
        elif button_choice.keys=='2': showselection_blue.setOpacity(1)
        elif button_choice.keys=='3': showselection_black.setOpacity(1)
       
        # *showselection_pink* updates
        if t >= 3.0 and showselection_pink.status == NOT_STARTED:
            # keep track of start time/frame for later
            showselection_pink.tStart = t  # underestimates by a little under one frame
            showselection_pink.frameNStart = frameN  # exact frame index
            showselection_pink.setAutoDraw(True)
        elif showselection_pink.status == STARTED and t >= (3.0 + 0.5):
            showselection_pink.setAutoDraw(False)
       
        # *showselection_blue* updates
        if t >= 3.0 and showselection_blue.status == NOT_STARTED:
            # keep track of start time/frame for later
            showselection_blue.tStart = t  # underestimates by a little under one frame
            showselection_blue.frameNStart = frameN  # exact frame index
            showselection_blue.setAutoDraw(True)
        elif showselection_blue.status == STARTED and t >= (3.0 + 0.5):
            showselection_blue.setAutoDraw(False)
       
        # *showselection_black* updates
        if t >= 3.0 and showselection_black.status == NOT_STARTED:
            # keep track of start time/frame for later
            showselection_black.tStart = t  # underestimates by a little under one frame
            showselection_black.frameNStart = frameN  # exact frame index
            showselection_black.setAutoDraw(True)
        elif showselection_black.status == STARTED and t >= (3.0 + 0.5):
            showselection_black.setAutoDraw(False)
       
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            routineTimer.reset()  # if we abort early the non-slip timer needs reset
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in trialComponents:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
       
        # check for quit (the [Esc] key)
        if event.getKeys(["escape"]):
            core.quit()
       
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
   
    #-------Ending Routine "trial"-------
    for thisComponent in trialComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    serPort.write(getT)
   
    # check responses
    if len(button_choice.keys) == 0:  # No response was made
       button_choice.keys=None
    # store data for trials (TrialHandler)
    trials.addData('button_choice.keys',button_choice.keys)
    if button_choice.keys != None:  # we had a response
        trials.addData('button_choice.rt', button_choice.rt)
   
   
    #------Prepare to start Routine "outcome"-------
    t = 0
    outcomeClock.reset()  # clock
    frameN = -1
    routineTimer.add(4.000000)
    # update component parameters for each repeat
    serPort.write(getT)
    core.wait(thermode_delay)
   
    if outcome=='win':
        serPort.write(outcome_temp_win)
        #core.wait(thermode_delay)
        print serPort.readline()
    if outcome=='lose':
        serPort.write(outcome_temp_lose)
        #core.wait(thermode_delay)
        print serPort.readline()
   
    if button_choice.keys=='1':
        if outcome=='win':
            outcome_win.setOpacity(1)
            outcome_win.setText(outcome_win.text)
            outcome_loss.setOpacity(0)
            outcome_loss.setText(outcome_loss.text)
        elif outcome=='lose':
            outcome_loss.setOpacity(1)
            outcome_loss.setText(outcome_loss.text)
            outcome_win.setOpacity(0)
            outcome_win.setText(outcome_win.text)
        elif outcome=='neut':
            outcome_loss.setOpacity(0)
            outcome_loss.setText(outcome_loss.text)
            outcome_win.setOpacity(0)
            outcome_win.setText(outcome_win.text)
    elif button_choice.keys=='2':
        if outcome=='win':
            outcome_win.setOpacity(1)
            outcome_win.setText(outcome_win.text)
            outcome_loss.setOpacity(0)
            outcome_loss.setText(outcome_win.text)
        elif outcome=='lose':
            outcome_loss.setOpacity(1)
            outcome_loss.setText(outcome_loss.text)
            outcome_win.setOpacity(0)
            outcome_win.setText(outcome_win.text)
        elif outcome=='neut':
            outcome_loss.setOpacity(0)
            outcome_loss.setText(outcome_loss.text)
            outcome_win.setOpacity(0)
            outcome_win.setText(outcome_win.text)
    else:
        outcome_win.setOpacity(0)
        outcome_win.setText(outcome_win.text)
        outcome_loss.setOpacity(0)
        outcome_loss.setText(outcome_loss.text)
   
    serPort.write(goT)
    print serPort.readline()
    outcome_win.setOpacity(0)
    outcome_loss.setOpacity(0)
    outcome_neut.setOpacity(1)
    # keep track of which components have finished
    outcomeComponents = []
    outcomeComponents.append(outcome_win)
    outcomeComponents.append(outcome_loss)
    outcomeComponents.append(outcome_neut)
    for thisComponent in outcomeComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
   
    #-------Start Routine "outcome"-------
    continueRoutine = True
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = outcomeClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        lastCall = 0
        if t>(lastCall+1.0):
            serPort.write(getT)
            lastCall = t
       
        # *outcome_win* updates
        if t >= 0.0 and outcome_win.status == NOT_STARTED:
            # keep track of start time/frame for later
            outcome_win.tStart = t  # underestimates by a little under one frame
            outcome_win.frameNStart = frameN  # exact frame index
            outcome_win.setAutoDraw(True)
        elif outcome_win.status == STARTED and t >= (0.0 + 4):
            outcome_win.setAutoDraw(False)
       
        # *outcome_loss* updates
        if t >= 0.0 and outcome_loss.status == NOT_STARTED:
            # keep track of start time/frame for later
            outcome_loss.tStart = t  # underestimates by a little under one frame
            outcome_loss.frameNStart = frameN  # exact frame index
            outcome_loss.setAutoDraw(True)
        elif outcome_loss.status == STARTED and t >= (0.0 + 4):
            outcome_loss.setAutoDraw(False)
       
        # *outcome_neut* updates
        if t >= 0.0 and outcome_neut.status == NOT_STARTED:
            # keep track of start time/frame for later
            outcome_neut.tStart = t  # underestimates by a little under one frame
            outcome_neut.frameNStart = frameN  # exact frame index
            outcome_neut.setAutoDraw(True)
        elif outcome_neut.status == STARTED and t >= (0.0 + 4):
            outcome_neut.setAutoDraw(False)
       
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            routineTimer.reset()  # if we abort early the non-slip timer needs reset
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in outcomeComponents:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
       
        # check for quit (the [Esc] key)
        if event.getKeys(["escape"]):
            core.quit()
       
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
   
    #-------Ending Routine "outcome"-------
    for thisComponent in outcomeComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    print serPort.readline()
    serPort.write(getT)
   
    #------Prepare to start Routine "VAS_intensity_2"-------
    t = 0
    VAS_intensity_2Clock.reset()  # clock
    frameN = -1
    routineTimer.add(5.000000)
    # update component parameters for each repeat
    serPort.write(getT)
    VASIntensity.reset()
    # keep track of which components have finished
    VAS_intensity_2Components = []
    VAS_intensity_2Components.append(VASIntensity)
    for thisComponent in VAS_intensity_2Components:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
   
    #-------Start Routine "VAS_intensity_2"-------
    continueRoutine = True
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = VAS_intensity_2Clock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        lastCall = 0
        if t>(lastCall+1.0):
            serPort.write(getT)
            lastCall = t
        # *VASIntensity* updates
        if t > 0.0:
            VASIntensity.draw()
            continueRoutine = VASIntensity.noResponse
            if VASIntensity.noResponse == False:
                VASIntensity.response = VASIntensity.getRating()
                VASIntensity.rt = VASIntensity.getRT()
       
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            routineTimer.reset()  # if we abort early the non-slip timer needs reset
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in VAS_intensity_2Components:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
       
        # check for quit (the [Esc] key)
        if event.getKeys(["escape"]):
            core.quit()
       
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
   
    #-------Ending Routine "VAS_intensity_2"-------
    for thisComponent in VAS_intensity_2Components:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    serPort.write(getT)
    trials.addData('VASIntensity.response', VASIntensity.getRating())
    trials.addData('VASIntensity.rt', VASIntensity.getRT())
   
    #------Prepare to start Routine "VAS_UnAngenehm"-------
    t = 0
    VAS_UnAngenehmClock.reset()  # clock
    frameN = -1
    routineTimer.add(5.000000)
    # update component parameters for each repeat
    serPort.write(getT)
    VASUnangenehm.reset()
    # keep track of which components have finished
    VAS_UnAngenehmComponents = []
    VAS_UnAngenehmComponents.append(VASUnangenehm)
    for thisComponent in VAS_UnAngenehmComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
   
    #-------Start Routine "VAS_UnAngenehm"-------
    continueRoutine = True
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = VAS_UnAngenehmClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        lastCall = 0
        if t>(lastCall+1.0):
            serPort.write(getT)
            lastCall = t
        # *VASUnangenehm* updates
        if t > 0.0:
            VASUnangenehm.draw()
            continueRoutine = VASUnangenehm.noResponse
            if VASUnangenehm.noResponse == False:
                VASUnangenehm.response = VASUnangenehm.getRating()
                VASUnangenehm.rt = VASUnangenehm.getRT()
       
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            routineTimer.reset()  # if we abort early the non-slip timer needs reset
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in VAS_UnAngenehmComponents:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
       
        # check for quit (the [Esc] key)
        if event.getKeys(["escape"]):
            core.quit()
       
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
   
    #-------Ending Routine "VAS_UnAngenehm"-------
    for thisComponent in VAS_UnAngenehmComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    serPort.write(getT)
    trials.addData('VASUnangenehm.response', VASUnangenehm.getRating())
    trials.addData('VASUnangenehm.rt', VASUnangenehm.getRT())
   
    #------Prepare to start Routine "end_trial"-------
    t = 0
    end_trialClock.reset()  # clock
    frameN = -1
    routineTimer.add(5.000000)
    # update component parameters for each repeat
    serPort.write(getT)
    core.wait(thermode_delay)
    print serPort.readline()
   
    serPort.write(stimulustemp)
    print serPort.readline()
    core.wait(thermode_delay)
    # keep track of which components have finished
    end_trialComponents = []
    end_trialComponents.append(end)
    for thisComponent in end_trialComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
   
    #-------Start Routine "end_trial"-------
    continueRoutine = True
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = end_trialClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        lastCall = 0
        if t>(lastCall+1.0):
            serPort.write(getT)
            lastCall = t
       
        # *end* updates
        if t >= 0.0 and end.status == NOT_STARTED:
            # keep track of start time/frame for later
            end.tStart = t  # underestimates by a little under one frame
            end.frameNStart = frameN  # exact frame index
            end.setAutoDraw(True)
        elif end.status == STARTED and t >= (0.0 + 5.0):
            end.setAutoDraw(False)
       
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            routineTimer.reset()  # if we abort early the non-slip timer needs reset
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in end_trialComponents:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
       
        # check for quit (the [Esc] key)
        if event.getKeys(["escape"]):
            core.quit()
       
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
   
    #-------Ending Routine "end_trial"-------
    for thisComponent in end_trialComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    serPort.write(getT)
   
    serPort.flushInput()
    serPort.flushOutput()
   
    serPort.write(getT)
    thisExp.nextEntry()
   
# completed 24 repeats of 'trials'
win.close()
core.quit()

susanne...@mail.mcgill.ca

unread,
Feb 5, 2014, 3:52:32 PM2/5/14
to psychop...@googlegroups.com
Hi all,

just an update on this issue: when I use a different newer computer with more RAM It takes much longer until the program freezes. By using this computer, I realized that the loop actually doesn't stop after 24 trials as it is stated in the program. I can't find the reason for this. Using the builder I created a loop, put in for $nRep 24 and a conditionsFile with 25 lines - the first line as a header and the following 24 for the conditions of the trials.

Has anyone an idea what might cause (1) the freezing of the program and (2) the repetition trials more than 24 time as stated in the loop?
As I really have no idea how to continue, any though would be welcome...
Susanne

Jeremy Gray

unread,
Feb 5, 2014, 4:00:45 PM2/5/14
to psychop...@googlegroups.com
Hi Susanne,

nReps=24 means: do the **set** of trials 24 times, where one set consists of all the conditions listed in the conditions file. So if I understand your situation, you actually are asking for 24 repetitions of 24 conditions = 576 trials. So try setting nReps to 1 -- that of itself might sidestep the memory problem. 


--Jeremy


--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/63be38ba-b655-4149-98a2-145d21833054%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

susanne...@mail.mcgill.ca

unread,
Feb 5, 2014, 5:34:50 PM2/5/14
to psychop...@googlegroups.com
oh, thanks!
That was a stupid error...I  got this completely wrong.
Susanne

susanne...@mail.mcgill.ca

unread,
Feb 7, 2014, 3:50:17 AM2/7/14
to psychop...@googlegroups.com
Dear all,

when I put in the right number (=1) for the conditions, I can run the program in the reduced version I posted above with the better computer. However, when I include all parts of the program, which are in addition some movies and a part where participants regulate the applied stimulation (heat) themselves via a response unit (transmitted through the serial port), the program still doesn't run through. I don't understand this, as the computer I'm using is not terribly old, the movies are not huge files, and the self-regulation part is only commands send to the serial port and read from it. I implemented exactly the same program before in NBS presentation and eprime without any problems. So I guess it's not the computer or similar.
What might cause this problem? Has anyone an idea if there is e.g. some temporary date that has to be cleared after each trial or similar?
As much as I'm convinced now by psychopy after using it only for a very short time, this bother me a lot as I have no idea how to find the error and how to procede (or start the actual experimental testing). Is there anymore information I can give, for someone to understand the problem better?

Thanks in advance!
Susanne

Jonathan Peirce

unread,
Feb 8, 2014, 7:00:49 AM2/8/14
to PsychoPy Users
There was a bug fix for a memory leak with movies, which was released in version 1.79.01. That version isn't being auto-updated but you can download the zip file from here:
and manually apply that using PsychoPy's update system.

That might solve your problem.

best wishes,
Jon




For more options, visit https://groups.google.com/groups/opt_out.



--

susanne...@mail.mcgill.ca

unread,
Feb 10, 2014, 4:46:13 AM2/10/14
to psychop...@googlegroups.com, j...@peirce.org.uk
Hi Jon,

thank you very much. I downloaded and installed the update. It seems to work a bit longer now (about 8 instead of 5 trials). However, it then stops again.
I also tried the version without the movies again on a fast computer, but it broke down too. So it seems that it was luck that it run through the last time I tested it without the movies.

Any other ideas?
Susanne

susanne...@mail.mcgill.ca

unread,
Feb 14, 2014, 7:42:32 AM2/14/14
to psychop...@googlegroups.com, j...@peirce.org.uk
Hi all again,

I still didn't get any further with the problem described above...However, instead of "just" freezing, it sometimes happens that psychopy stops in the middle of the running program, showing a white screen (or more likely the background, which I set in this experiment to white). In this case I can't escape the program by pressing escape. I don't get an error message. Moreover, I can't run a program after such a stop, i.e. the program starts but only a white screen shows and again I can't escape by pressing escape. Even when I shut down Psychopy and restart it, it won't work. The only thing that helps is shutting down the computer and restarting everything.
Does anybody know what this means? When does it usually happen that psychopy stops working like this?

Susanne

Jonathan Peirce

unread,
Feb 14, 2014, 7:50:06 AM2/14/14
to psychop...@googlegroups.com
I'm afraid I have no idea. I've never managed to get a mac to freeze like this from psychopy. And you say it's nothing to do with movies after all? So, if you go to the stroop demo and set it to 100 trials it freezes there too?

I'm trying to work out if this is a problem with your computer or something in the experiment. If stroop works and your experiment doesn't then the idea is to gradually change the experiment until you find the smallest version that 'breaks'. Then we know where to look.

cheers
Jon

For more options, visit https://groups.google.com/groups/opt_out.

-- 
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it.   Please do not use, copy or disclose the information contained in this message or in any attachment.  Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system, you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.


susanne...@mail.mcgill.ca

unread,
Feb 14, 2014, 11:35:28 AM2/14/14
to psychop...@googlegroups.com
Thanks, Jon.
The stroop example runs even if I do more then 100 trials.
The strategy of reducing the program gradually is exactly what we have been doing. We got so far that a very short version of the program worked.This only included a routine in which a picture is presented and subjects press one of two buttons, which are represented on the screen by two colored squares. The choice then is highlighted. In addition the initialization of the external heat device I'm using is included as well as a watch dog procedure during the picture presentation and button press, i.e. sending a command at latest every 2 sec to keep up a handshake with the external device. When we then include one of two VAS, the program freezes again, here typically with showing the white screen and no option of escaping with the button press escape.
I can't find something special about my VAS; I used the component in the builder and adjusted it a bit.
The movies seem to be not the problem as we have a reduced version of the program with the movies, but almost nothing else, that works...at least for the 24 trials we want to do. We haven't finished testing all possible versions excluding and including all possible options of the program to definitely see which part is causing the problem (as there are actually quiet a lot of possibilities...), but as I wrote above, including the VAS caused a problem

cheers,
Susanne
...

susanne...@mail.mcgill.ca

unread,
Feb 17, 2014, 11:20:48 AM2/17/14
to psychop...@googlegroups.com
here another update, possibly it sounds familiar to someone.
We now figured that the crash of psychpy, where it is not longer possible to exit the running program with escape and where we have to restart the computer, always happens, when we run a psychopy program once or even if we run it only in part (i.e. a few trials). This happens only with the program and its versions which reduced numbers of routines that I have created in the builder. It also happens on different computers but it doesn't happen with the demo programs.
Has anyone an idea what I might have included that causes these crashes?

In addition, I still get the freezing of the program when I run the complete version, i.e. including all parts I need for the experiment as I put it together from the beginning. I'm not sure if these problems might be related.
Susanne
...

Michael MacAskill

unread,
Feb 17, 2014, 7:28:10 PM2/17/14
to psychop...@googlegroups.com
Dear Susanne,

So it sounds to me like you have isolated the problem to the visual analog scale. Are you able to make a file that contains only that, which reliably causes the crash, and share it with us here?

Regards,

Michael

susanne...@mail.mcgill.ca

unread,
Feb 18, 2014, 11:01:38 AM2/18/14
to psychop...@googlegroups.com
Dear all,

after some more quite extensive testing, we found out that it is actually not the VAS itself, causing this problem.
I had in the code components several time the command serial.readline() as I wanted to know what my heat device connected to the serial port, is doing in response to the commands send. It makes actually not much sense to me, but when I delete all readline() commands the program is running. Related to that I really don't understand why this problem occurs in one of our program versions with the VAS but not in the same version without the VAS. In both versions nothing was changed related to the serial port, i.e. all the commands for the serial port where the same in both versions.
However, with one version, I could precisly pin the problem down to the readline() command, as it always worked without but not with.

Although the program seem ok now, it still happens about every third run that after running through the whole program without any problems, I can't start it again. All I see then is a white screen and nothing happens. I can't exit this with the escape key and to get psychopy running again, I have to restart the computer. What might cause this crash of the program?

Thanks for your help!
Susanne

Jeremy Gray

unread,
Feb 18, 2014, 11:13:22 AM2/18/14
to psychop...@googlegroups.com
Hi Susanne,

Glad to hear you are making progress. 

You might get a hint about the cause of the white-screen crash if you run with a non-full-screen window. Keep starting the script until a crash happens, then switch away from the psychopy window and look for an error message. Any clue here would help.

--Jeremy

--Jeremy


--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.

susanne...@mail.mcgill.ca

unread,
Feb 20, 2014, 5:47:22 AM2/20/14
to psychop...@googlegroups.com
Hi Jeremy,

I tried what you suggested but unfortunately I didn't get any error message with the crash. However, I guess I solved it, although, again, I don't understand it exactly...I included in the program some flush() commands for the serial input and output. With that it don't happen anymore that the script can't be stared again once it had run.
But still, there is some weird behavior. Although the program doesn't crash anylonger it happens about every third or fourth time that the commands seem to be send to the serial port in a wrong fashion. When this happens, my temperature device is cooling constantly down instead of increasing the temperature. Usually this happens when the command through the serial port are send too fast. To prevent this I included a delay of 50ms after each command send to the serial port - in theory. In practice it seems to happen anyhow. What I find strange is that it only happens about every 3rd or 4th time when I start the script. If I then stop the script and start it again (without restarting the program/computer) all is fine again.
It there another function in addition to the serial.flush(), serial.flushInput(), or serial.flushOutput() with which I can control what is in the serial buffer?

Do you have by any change an idea what might be the reason, why I only getting this problem in about a third of the runs (which is still too often for running it in a real experiment...)?
Thanks!
Susanne

susanne...@mail.mcgill.ca

unread,
Feb 24, 2014, 10:14:41 AM2/24/14
to psychop...@googlegroups.com
Hi!

all solve now! It seems that psychopy is too fast ;) I added some more delay for the heat device to receive the commands via the serial port and now eveything works. I'm not a 100% happy with this solution as these delays add up to ca. 500 ms per trial, but it works.

Out of curiosity, has someone an idea why the serial.readline command might have cause the problems I had before, i.e. the crashing of the program?
Susanne

Jonathan Peirce

unread,
Feb 24, 2014, 12:53:25 PM2/24/14
to psychop...@googlegroups.com
It isn't clear to me that the program is 'crashing'. For example, if you've told it to wait indefinitely for a string to be sent back on the serial port, but no such string is received (e.g. because the device didn't notice that it had received a command) then it will continue waiting. If inserting pauses fixes the problem then this seems plausible. It's maybe just following your instruction to wait?

Jon

For more options, visit https://groups.google.com/groups/opt_out.

Barb Lahey

unread,
Feb 1, 2016, 1:50:39 PM2/1/16
to psychopy-users
 I believe I have a similar issue to the one here. However, I do not have a heating device. My problem is that Psychopy will freeze anytime I press Escape to end my experiment early. I end up having to press control alt delete to abort all of psychopy. The escape key is permitted in my experiment settings. I also tried running on a small screen to see if I get an error message, and I do not get any messages.

Does anyone know why this may be?

Thank you for your time and help!
Danielle
...

Michael MacAskill

unread,
Feb 1, 2016, 3:47:57 PM2/1/16
to psychop...@googlegroups.com
Dear Danielle,

Are you using any code in a code component that checks the keyboard?

This can often compete with Builder's own checking for the escape key, meaning that it gets missed. What happens then is that PsychoPy isn't really freezing, it just isn't detecting 'escape'.

Regards,

Michael



> On 2/02/2016, at 07:50, Barb Lahey <barbla...@gmail.com> wrote:
>
> I believe I have a similar issue to the one here. However, I do not have a heating device. My problem is that Psychopy will freeze anytime I press Escape to end my experiment early. I end up having to press control alt delete to abort all of psychopy. The escape key is permitted in my experiment settings. I also tried running on a small screen to see if I get an error message, and I do not get any messages.
>
> Does anyone know why this may be?
>
> Thank you for your time and help!
> Danielle

--
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill

Barb Lahey

unread,
Feb 1, 2016, 4:45:14 PM2/1/16
to psychopy-users
I'm sorry what do you mean by checking the keyboard?

Wouldn't psychopy continue with the program if it isn't freezing? I am getting a full freeze and must abort the program via Control alt delete.

Thank you as always!
Reply all
Reply to author
Forward
0 new messages