Add a call to quit to make the thread ending the loop