title: Stop mp3 fille which is in loop
body: <p>I want to stop the mp3 file immediately at key stroke by user. Here is my code:</p>
  <pre><code>From pygame import mixer
  Import time
  
  def music(file) :
      mixer.init()
      mixer.music.load(file)
      while True :
          try :
             mixer.music.play() # duration of file 2 sec
             time.sleep(3)
          except KeyboardInterrupt :
             mixer.music.stop()
             break
  </code></pre>
  <p>Now it works, it stop the loop but after complete the playing the whole mp3. I want it to stop immediately just like an alarm. Although same file in <code>py.exe</code> stop the loop immediately. But not in IDLE.</p>