Running a python script for a user-specified amount of time?

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-05-14T04:08:55Z Indexed on 2010/05/14 4:14 UTC
Read the original article Hit count: 158

Filed under:

Sorry, this is probably a terrible question. I've JUST started learning python today. I've been reading a Byte of Python. Right now I have a project for Python that involves time. I can't find anything relating to time in Byte of Python, so I'll ask you:

How can I run a block for a user specified amount of time and then break?

For example (in some pseudo-code):

time = int(raw_input('Enter the amount of seconds you want to run this: '))
while there is still time left:
    #run this block

or even better:

import sys
time = sys.argv[1]
while there is still time left:
    #run this block

Thanks for any help. Also, additional online guides and tutorials would be much appreciated. I really like Byte of Python. Dive into Python can't quite hold my attention, though. I suppose I should suck it up and try harder to read that one.

© Stack Overflow or respective owner

Related posts about python