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

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2

    Timer expired or not


    Dear all.

    How can check timer expired or not in python

    i wanna do this
    import time
    while(time.sleep(60)):
    dothis
    else
    do this
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    530
    Rep Power
    34
    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.
    Code:
    import datetime
    
    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 05:12 PM.

IMN logo majestic logo threadwatch logo seochat tools logo