Howdy, Stranger!

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

Supported by

[solved] pygaze multithreading

edited October 2014 in PyGaze

Hi,
Thanks for this set of libraries, it looks very much like what I need. I'm fairly new to python and this is helping me progress quickly.
Currently I want to present an animated fixation screen while waiting for a condition to come true. I tried launching the function for the animation (basically looping through a set of screens) in a separate thread with the idea of testing the condition in the main thread and killing the fixation thread when the condition became true, however this approach seems to cause a seg fault.
Is is possible to use pygaze in a multi-threaded environment? If so are there any examples of how this can be done?
Thanks
Tom

Comments

  • edited 12:40PM

    Hi Tom,

    Thanks, and welcome to the forum! Whether PyGaze is multithreading-safe depends on what OS you use, and what you're doing in each of the threads.

    Under Linux, trying to communicate with the X server from different threads results in a hard crash, which means that if you're displaying your animated fixation via the main thread, and simply check for a timeout in a subthread you should be ok. However, if you're parsing samples in the subthread, using the one of the eyetracker classes, you might run into trouble (because these classes have built-in display functionality). As you suggest doing the opposite (running the fixation in the subthread, while checking for the condition in the main thread), you're going to have a problem under Linux anyway. Surprisingly, this is no problem under Windows (where Python's multithreading module behaves differently).

    You could opt for a sequential solution, by doing both the checking for your condition and displaying the animated fixation cross from within the same loop. If you're not doing anything too complicated, this shouldn't affect the animation smoothness. An example:

    ###
    # imports, preparation, and other stuff here
    ###
    
    # central fixation position
    fixpos = (DISPSIZE[0]/2, DISPSIZE[1]/2)
    
    # iterator and sentry variable
    i = 0
    condition = False
    
    # loop until a condition is met
    while not condition:
        # check for a sample on fixpos
        gazepos = tracker.sample()
        if (gazepos[0] - fixpos[0])**2 + () < maximal_error:
            contition = True
        # update the animation
        disp.fill(animfixscreens[i])
        disp.show()
        # update iterator
        if i >= len(animfixscreens)-1:
            i = 0
        else:
            i += 1
        # optional: pause for a bit
        # (not necessary when using blocking flip under PsychoPy)
        # libtime.pause(10)
    

    This snippet shows how you loop through a list of Screen objects, animfixscreens (each containing a different frame of your animated fixation), whilst also checking whether the current gaze position is at the desired fixation position. You can add complexity as you like, for example to keep track of how many consecutive samples have been at the desired fixation location and to break after a certain number (or fixation duration).

    Does this help you at all? If not, please elaborate on the specifics of your experiment are (i.e.: what condition are you checking for, and how is your animated stimulus presented).

    Good luck!

    Edwin

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 http://45.77.173.118/ 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