Python Forum
How to Kill Dead Loop of "while"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Kill Dead Loop of "while"
#4
The focus must be on the terminal window, to send CTRL+C to it.
If your mp3 player program is in front, the terminal windows won't receive CTRL+C.
In previous Python versions were a bug with catching CTRL+C on Windows.
The current version 3.7.4 does not have this problems (I use it sometimes on window).

I guess you want to start the mp3-files with the linked application.
os.system is normally used to run executable files. os.startfile (Windows only) is used to do what you are doing with os.system. Also os.system is marked as deprecated. To start executable files, the subprocess module should be used.

If you want to catch the error message (SIGINT) in very simple program, you can just use the try-except block:

def main():
    """
    Your main programm function, which calls other functions etc...
    """

try:
    main()
except KeyboardInterrupt:
    print('Got CTRL+C, quit program.')
For completeness, to avoid execution of your code, if you import it from other modules, you should add the if __name___ = '__main__' boilerplate code.


def main():
    """
    Your main programm function, which calls other functions etc...
    """

if __name__ == '__main__':
    # this is only executed, if you run this module directly with python
    # this block is not executed, if you import this module.
    try:
        main()
    except KeyboardInterrupt:
        print('Got CTRL+C, quit program.')
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
How to Kill Dead Loop of "while" - by cheers100 - Aug-22-2019, 04:40 AM
RE: How to Kill Dead Loop of "while" - by Aravind_K - Aug-22-2019, 04:46 AM
RE: How to Kill Dead Loop of "while" - by Malt - Aug-22-2019, 04:50 AM
RE: How to Kill Dead Loop of "while" - by DeaD_EyE - Aug-22-2019, 07:20 AM
RE: How to Kill Dead Loop of "while" - by cheers100 - Aug-22-2019, 09:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  os.kill elstolbo 1 2,420 Jan-26-2020, 04:13 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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