Jump to content

python quit command?

Stevoicus

i know you can tell a program to "quit()" in python with that command in say an if statement or whatever but i want a command that says something like "quit after 10 seconds" to the program?

Anyone help me?

Link to comment
Share on other sites

Link to post
Share on other sites

Well I belief there is a quit() command, otherwise you could use sys.exit(). The last one (not sure about the first) will stop the current thread(), keep that in mind if you are writing multithreaded code. It's not a very nice solution though. I rather work with flags, so I have a flag which is True until it encounters the reason I want it to stop, then I set it to False and in the if statement I say if check == True.

PSU tier list // Motherboard tier list // Community Standards 

My System:

Spoiler

AMD Ryzen 5 3600, Gigabyte RTX 3060TI Gaming OC ProFractal Design Meshify C TG, 2x8GB G.Skill Ripjaws V 3200MHz, MSI B450 Gaming Plus MaxSamsung 850 EVO 512GB, 2TB WD BlueCorsair RM850x, LG 27GL83A-B

Link to comment
Share on other sites

Link to post
Share on other sites

i know you can tell a program to "quit()" in python with that command in say an if statement or whatever but i want a command that says something like "quit after 10 seconds" to the program?

Anyone help me?

yes i know there is the quit() command like is said... i need one that ends the program after a specified amount of time

Link to comment
Share on other sites

Link to post
Share on other sites

Oooh sorry, didn't understand it correctly. You can use the time function.

 

import time

time1 = time.time()

time2 = time.time()

while time2-time1 < 10:

    Do whatever needs to be done

    time2 = time.time()

PSU tier list // Motherboard tier list // Community Standards 

My System:

Spoiler

AMD Ryzen 5 3600, Gigabyte RTX 3060TI Gaming OC ProFractal Design Meshify C TG, 2x8GB G.Skill Ripjaws V 3200MHz, MSI B450 Gaming Plus MaxSamsung 850 EVO 512GB, 2TB WD BlueCorsair RM850x, LG 27GL83A-B

Link to comment
Share on other sites

Link to post
Share on other sites

Or if you don't need to do things during the time:

 

import sysimport time time.sleep(10)sys.exit()

 

Will exit after ten seconds.

--Neil Hanlon

Operations Engineer

Link to comment
Share on other sites

Link to post
Share on other sites

Depending on what you're doing you can use exit() or sys.exit(), the latter likely being the one you want to use.

"Unix was not designed to stop you from doing stupid things, because that would also stop you from doing clever things." - Doug Gwyn

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×