March 11th, 2013, 11:46 PM
Timer expired or not
How can check timer expired or not in python
i wanna do this
March 12th, 2013, 12:31 AM
Nothing happens during time.sleep() so you have to store a start time and compare it to the time on each pass through the while loop. This example uses datetime and is perhaps overkill but I generally use datetime so am only familiar with it.
stop = datetime.timedelta(seconds=1) ## run for one second
ctr = 0
start_time = datetime.datetime.now()
diff = start_time - start_time ## initialize at zero
while diff < stop:
ctr += 1
diff = datetime.datetime.now() - start_time
print ctr, diff
Last edited by dwblas; March 12th, 2013 at 04:12 PM.