Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exit Function - loop
#3
(Sep-17-2020, 08:05 AM)cnull Wrote: Does this work right?

def songplay(song):
    with outport as output:
        try:
            midifile = MidiFile(song)
            while True:
                for message in midifile.play():    
                    output.send(message)

Yes, in fact his is the code, actuall I have an expet KeyboardInterrupt ... but yes it Works

def songplay(song):
    with outport as output:
        try:
            midifile = MidiFile(song)
            while True:
                for message in midifile.play():    
                    output.send(message)
 
        except KeyboardInterrupt:
            print()
            output.reset() 
Reply


Messages In This Thread
Exit Function - loop - by Tetsuo30 - Sep-17-2020, 07:54 AM
RE: Exit Function - loop - by cnull - Sep-17-2020, 08:05 AM
RE: Exit Function - loop - by Tetsuo30 - Sep-17-2020, 09:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python difference between sys.exit and exit() mg24 1 1,902 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  Exit function from nested function based on user input Turtle 5 2,979 Oct-10-2021, 12:55 AM
Last Post: Turtle
  While loop doesn't exit KenHorse 3 2,063 Jun-20-2021, 11:05 PM
Last Post: deanhystad
  function fails to exit harig3 4 2,080 Aug-17-2020, 06:35 PM
Last Post: deanhystad
  Using Function in a For loop vp1989 5 2,871 May-19-2020, 03:53 PM
Last Post: vp1989
  Struggling to exit this while loop fatherted99 5 2,535 Feb-08-2020, 07:46 PM
Last Post: fatherted99
  won't exit a loop, please help hobbyprogrammer 9 4,451 Oct-22-2018, 05:22 PM
Last Post: hobbyprogrammer
  Using break to exit a loop help JJG 4 4,227 Dec-09-2017, 03:02 AM
Last Post: JJG
  How to exit infinite While Loop? Fran_3 3 4,136 Aug-10-2017, 05:29 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020