J. Pinheiro
J. Pinheiro

Reputation: 55

How to stop console from exiting

I want the program to wait like 5 seconds before exiting the console after finishing whatever it does, so the user can read the "Good Bye" message, how can one do this?

Upvotes: 0

Views: 122

Answers (3)

Marius M
Marius M

Reputation: 496

If it's not a multithreaded program, then just let the program do whatever it needs and then: raw_input("Press Enter to stop the sharade.\n") Maybe it's not exactly what you're looking for but on the other hand you should not rely on a predefined sleep time.

Upvotes: 0

Pynchia
Pynchia

Reputation: 11590

You can register an Exit Handler, so that when the program exits/ends, possibly in multiple points in the code, a designated function is called.

The handler can print a message, sleep for a few seconds then exit.

import atexit
import time

@atexit.register
def goodbye():
    print "Goodbye dear user"
    time.sleep(5)

Please read the official documentation here

Upvotes: 2

Hackaholic
Hackaholic

Reputation: 19733

you can use time.sleep:

import time
print "Your GoodBye Message"
time.sleep(5)

Upvotes: 1

Related Questions