Thread: on exit

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25

    on exit


    I am looking for a way to have my computer do a function when the user terminates the app by ctrl-c, i am not to worried about other methods but if your way can handle more than just ctrl-c then i would love to see that too.

    Any ideas?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    17
    In python you would catch the keyboard interrupt exception:
    Code:
    ...
    try:
    
        run the main program
    
    except KeyboardInterrupt:
        do something else
    Just a somewhat stupid example for illustration:

    Code:
    import time
    
    try:
        for i in range(100):
            print i
            time.sleep(1)
    except KeyboardInterrupt:
        print "Ouch!"

IMN logo majestic logo threadwatch logo seochat tools logo