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 2018 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!

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')
    key, time = my_keyboard.get_key()
    if key=='return':
        self.experiment.set("response", resp)
        var.response_time = time - start_time
        var.error_km = int(resp) - var.corr_distance_km
    if key=='backspace':
        resp = resp[:-1]
        my_canvas.text(resp, y=y_center+150)
        resp += key
        my_canvas.text(resp, y =y_center+150)


  • 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?


  • 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.

  • edited May 2018

    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.

            key, time = my_keyboard.get_key()


  • 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.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games