Thresholding Freezing Laptop

Hello - I’m trying to create a signal detection task. Individuals will hear white noise and need to detect if there is a tone or not. Individual detection thresholds at 75%, 50% and 25% need to be attained (it will eventually be uploaded to Pavlovia - but I’ll cross that path later).
So far I’ve kept it simple with three routines: welcome page, thresholding trial, and end screen.
In the thresholding trial I’ve uploaded the audio files separately - using the builder. I’ve added a fixation cross and text (do you hear a tone?) and a key response(press left or right). In addition to the builder components I used code.

When I use this code:
from psychopy import core, visual, event, sound
import random

Define the volume range for the tone

min_volume = 0
max_volume = 1

Define the initial step size for adjusting the volume

step_size = 0.1

Define the detection thresholds for the participant

thresholds = [0.25, 0.5, 0.75]

Create a staircase handler for each threshold

stairs =
for threshold in thresholds:
step_sizes = [step_size]*10
stair = data.StairHandler(startVal=random.uniform(min_volume, max_volume),
extraInfo={‘threshold’: threshold})

Create a loop to run the trials

for trial_num in range(60):
# Get the volume for the current trial
volume = stairs[0].next()

# Determine if the tone should be played based on the volume
if volume > 0:
    tone = sound.Sound('FILEPATH', volume=volume)
    correct_resp = 'left'
    tone = sound.Sound(value=0)
    correct_resp = 'right'

# Create a loop to wait for a response
resp = None
while resp is None:
    # Play the white noise and the tone
    noise = sound.Sound('FILEPATH')

# Determine if the response was correct and update the staircase accordingly
if resp[0] == correct_resp:
    corr = 1
    corr = -1
for stair in stairs:
    if stair.extraInfo['threshold'] == thresholds[0]:

# Check if any of the staircases have reached the threshold
for stair in stairs:
    if stair.extraInfo['threshold'] == thresholds[0] and stair.finished:
        print('Threshold of {} reached for staircase {}'.format(thresholds[0],

# Check if all of the staircases have finished
if all([stair.finished for stair in stairs]):

(FILEPATH - I use the actual path). It runs the trial on the welcome screen and freezes the computer with the white noise playing.

Any help on what’s going wrong or how I could do this task.

I think the loop here is getting stuck:

resp = None
while resp is None:

You don’t update resp as part of this loop. If you have a keyboard response object called “resp” somewhere else in the code, you’re overwriting it with the “resp = None” declaration, so it’s not going to update. Furthermore because of that core.wait, you’re going to only be checking every 500ms anyway.

The loop needs to be reconfigured to be something like this:

resp = kb.getKeys() # assuming kb is a keyboard object you created previously
noise = sound.Sound('FILEPATH')
# Using a countdown clock instead of core.wait so you can check for a response on every frame
noiseCountdown = core.Clock()
while len(resp) == 0:
    if noiseCountdown.getTime <= 0:
    # If you don't want to allow a response before the tone plays, move this into the 'if' statement
    resp = kb.getKeys()

Something like that should work.

Thank you!