touchscreen and sound playing

Hey there,
I am having trouble running a psychological experiment where participants tap synchronously along with a perceived periodic beat. They make responses by using index finger to touch the computer screen. The periodic beat is an isochronous tone sequences, where a pure tone (600 Hz, 50ms duration) was presented every 600ms.
The program is running in a computer with touchscreen. If I don’t make responses, i.e. touch the screen, the program will run normally. However, if I tap along with the sound stimulus, the program will get stuck when the fifth tone or sixth tone plays, and the following tones can’t play.
In addition, I change the code, which uses keyboard to make the response instead of touchscreen. Then, the program runs normally. Is that the touch’s problem?
I don’t know how to solve this problem. Are there something wrong in my code?
Thank you in advance!

This is my code:

from __future__ import division

import sys
from psychopy import logging, prefs
logging.console.setLevel(logging.DEBUG)  # get messages about the sound lib as it loads

from psychopy import prefs
prefs.general['audioLib'] = ['sounddevice']

from psychopy import visual, event, core, sound
from psychopy import iohub

io = iohub.launchHubServer()
mouse = io.devices.mouse
win = visual.Window(monitor="testMonitor", units="norm",fullscr=True,allowGUI=False,color=[-1,-1,-1])
ll = sound.Sound('pure tone.wav')
IOI = .6
stim_delay = 0.05

file = open("H:/spatial tapping0422/record/con_sound_test_.txt",'w')
circle = visual.Circle(win, radius=7,edges=60,size=[0.001,0.001],fillColor='white',pos=[0,0])
circle.draw()
win.flip()
core.wait(0.6)
record1 = ''

for i in range(11):
    ll.play()
    playtime = core.getTime()
    record1 += ('1'+','+str(playtime)+','+'0'+','+'0'+'\n')
    while True:
        time_temp = core.getTime()
        if (time_temp - playtime) > stim_delay:
            break
        e = mouse.getEvents(event_type=iohub.constants.EventConstants.MOUSE_BUTTON_PRESS)
        if e:
            x, y, z = e[0].x_position, e[0].y_position, e[0].time
            record1 += ('9'+','+str(z)+','+str(x)+','+str(y)+'\n')
    ll.stop()
    while True:
        time_temp = core.getTime()
        if (time_temp - playtime) > IOI - stim_delay:
           break
        e = mouse.getEvents(event_type=iohub.constants.EventConstants.MOUSE_BUTTON_PRESS)
        if e:
            x, y, z = e[0].x_position, e[0].y_position, e[0].time
            record1 += ('9'+','+str(z)+','+str(x)+','+str(y)+'\n')

file.write(record1)