Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

While loop hangs (and it drives me nuts!) :(

edited May 16 in OpenSesame

Guys...i can't get my head around this so hopefully one of you could help. Here's the situation I'm facing. I prepared an experiment where I show on a canvas the names of two towns and ask participants to enter their estimate of the distance between them and press enter. I have a list with 171 pairs of towns and I randomly select a pair for each trial. Everything works well except that the experiment hangs at what seem to be a random point (i.e., different pair of towns each time, different point through the experiment). That is, I go through the experiment and at some point when a pair is presented, I enter my response, but nothing happens when I press enter. No error is printed and I have to close OS with control-alt-delete. I suspect it's something to do with the while loop I use to present the trials. I paste the code below for that loop...can anyone spot anything wrong with it? thanks in advance!
marios

while True:
    my_canvas.text(text=var.town1,x=x_center-200, y=y_center, color=u'white')
    my_canvas.text(text=var.town2,x=x_center+200, y=y_center, color=u'white')
    my_canvas.show()
    key, time = my_keyboard.get_key()
    if key=='return':
        my_canvas.clear()
        self.experiment.set("response", resp)
        var.response_time = time - start_time
        var.error_km = int(resp) - var.corr_distance_km
        break
    if key=='backspace':
        my_canvas.clear()
        resp = resp[:-1]
        my_canvas.text(resp, y=y_center+150)
    else:
        resp += key
        my_canvas.clear()
        my_canvas.text(resp, y =y_center+150)

Comments

  • Hi Marios,

    This loop is perfectly fine, in the sense that it's guaranteed to break when key == 'return'. Could it be that some other application steals the keyboard focus or something along those lines? Or perhaps the freezing occurs in some other part of the experiment?

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Thanks Sebastian. I'm running the experiment fullscreen...can the keyboard focus go to another app this way? I've tried it on multiple computers and get the same issue.

  • Aaaargh! I stripped my code to the bare essentials and still no luck. I attach my experiment which is pretty much one inLine that presents the names of two cities and asks the user to enter a number and press return. The program hangs after about 50-70 trials. If anyone could be kind enough to take a look I would really appreciate it.
    marios

  • edited May 21

    I fixed it I think,

    You should have added :

    #Here you should add enumerate and add an index variable 
    # since i is defined before
    for i, c in enumerate(range(len(list3))):
        #get a trial number in the data
        var.trialno = i+1
        resp =''"
    

    I think is better to fix the position of the target words as well since is not visible enough,
    Also if it doesn't log as you like you should play around with the position of i and c ...

    Hope it helps

    I attached the full thing below

  • Thanks Stavro. Unfortunately, it still hangs.

  • Hi Marios,

    It seems to be an issue with the event buffer, i.e. an internal buffer that keeps track of key presses, etc. I think it overflows, although I'm not sure why (yet). As a workaround, you can flush the keyboard before getting a key. Or use the psycho backend, which uses a different kind of event buffer.

            my_keyboard.flush()
            key, time = my_keyboard.get_key()
    

    Cheers!
    Sebastiaan

    Thanked by 1mariosav

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • You're a God! Thank Sebastiaan. I confirm that it works perfectly with flushing the keyboard. Thank you so much for this!

Sign In or Register to comment.