Howdy, Stranger!

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

Supported by

Opensesame Freezing when Running using Pygaze

Hello hello :)

I am running into a similar issue as has been experienced before, namely that my opensesame experiment freezes once the Pygaze init is set to calibrate the tracker.


The calibration works fine but once the stimulus presentation starts, it freezes after the first trial. It gets stuck on the last image frame, and when I click on the screen it says "python has stopped responding".


I have attempted to add a short delay at the end to try to prevent freezing. Note that this stimulus type requires a loop of multiple images.


I have attached a code example of an inline script used to present stimuli:


import os

import time


# Function to present complex stimuli

def present_complex_stimulus(complex_stim_prefix):

# Construct the list of image filenames

image_filenames = [f'{complex_stim_prefix}_{i}.png' for i in range(1, 10)]


for img_filename in image_filenames:

# Construct the full image path

img_path = os.path.join(image_dir, img_filename)


# Clear the canvas before showing the new image

my_canvas.clear()


# Show the new image

my_canvas.image(img_path, center=True, x=0, y=0, scale=var.image_scale)

my_canvas.show()


time.sleep(0.4) # Display each image for 400 ms


var.complex_stim_prefix = selected_set["complex_stim_prefix"]


# Present the complex stimulus

present_complex_stimulus(var.complex_stim_prefix)


# Resetting variables

started_lookingaway = False

insp_dur = 0

disconnect_dur = 0

lookaway_dur = 0


# Initialize trial-specific variables

var.t0 = time.time()

var.insp_dur = 0

var.lookaway_dur = 0

var.disconnect_dur = 0


# Eye tracking loop

while True:

# Get the current time at the start of the iteration

current_time = time.time()


# Calculate elapsed time from the start of the loop

elapsed_time = current_time - var.t0


# Sample gaze coordinates

x, y = eyetracker.sample()


if elapsed_time >= 5:

break # Exit the loop if the maximum duration is reached


if eyetracker.connected():

if var.x_min < x < var.x_max and var.y_min < y < var.y_max:

# If on target, log inspection duration and reset looking away timer

var.insp_dur = elapsed_time

var.lookaway_dur = 0

else:

# If not on target, append new time to looking away timer

var.lookaway_dur += (current_time - var.t0)

# If looking away for 1.5 or more seconds, run grabber_loop2

if var.lookaway_dur >= 1.5:

run_grabber = True

break

else:

# Increment disconnect duration

var.disconnect_dur += (current_time - var.t0)

if var.disconnect_dur >= 1.5:

break



# Check if the trial should end based on the specified conditions

if elapsed_time >= 5 or var.lookaway_dur >= 1.5:

break


# Update var.t0 to the current time at the end of the iteration

var.t0 = current_time


# Add a small delay to prevent freezing

time.sleep(0.01)


# Clear the canvas

my_canvas.clear()

my_canvas.show()


Could you spot anything in my code that may be causing an infinite loop? Or is this problem related to hardware?

Comments

  • Quick update: the experiment no longer freezes when i remove my attention grabber script:


    import os

    import time

    import pygame.mixer # Import the sound library


    # Initialize the sound mixer

    pygame.mixer.init()


    # Define the directory containing the image files

    image_dir = r"C:\Users\topuser\Desktop\HabTask-Complexity\stimuli"


    # Define the path to the single image file

    image_file = 'grabber1.png'


    # Define the path to the sound file (MP3 format)

    sound_file = r"C:\Users\topuser\Desktop\HabTask-Complexity\stimuli\calibration_target_audio.wav"


    # Function to display the image

    def display_image(image_file):

    # Construct the full image path

    img_path = os.path.join(image_dir, image_file)


    # Clear the canvas before showing the new image

    my_canvas.clear()


    # Show the image

    my_canvas.image(img_path, center=True, x=0, y=0, scale=var.image_scale)

    my_canvas.show()


    # Function to play the sound

    def play_sound(sound_file):

    # Load the sound file

    sound = pygame.mixer.Sound(sound_file)


    # Play the sound

    sound.play()


    # Add a small delay to prevent freezing

    time.sleep(0.1)


    # Function to monitor gaze

    def monitor_gaze():

    global run_grabber # Ensure run_grabber is recognized globally


    # Resetting variables

    started_lookingaway = False

    lookaway_dur = 0

    looking_at_grabber_dur = 0

    disconnect_dur = 0 # Ensure this variable is defined


    # Initialize t0 variable

    var.t0 = time.time()

    run_grabber = False


    # Sample gaze coordinates

    x, y = eyetracker.sample()


    if eyetracker.connected():

    if var.x_min < x < var.x_max and var.y_min < y < var.y_max:

    # If on target, reset lookaway duration and start counting

    lookaway_dur = 0

    if run_grabber:

    looking_at_grabber_dur += (time.time() - var.t0)

    if looking_at_grabber_dur >= 0.5:

    # Break the loop and continue to the next trial

    return

    else:

    looking_at_grabber_dur = 0

    else:

    # If not on target, increase lookaway duration

    lookaway_dur += (time.time() - var.t0)

    # If looking away for more than 1.5 seconds, set run_grabber to True

    if lookaway_dur >= 1.5:

    run_grabber = True

    return # Exit the function once the condition is met

    else:

    # Increment disconnect duration

    disconnect_dur += (time.time() - var.t0)

    if disconnect_dur >= 1.5:

    return


    # Display the image if run_grabber is True

    if run_grabber:

    # Display the image

    display_image(image_file)


    # Play the sound after displaying the image

    play_sound(sound_file)

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