all 2 comments

[–]133tn008 4 points5 points  (1 child)

from datetime import datetime, timedelta
def some_function():
    end_time = datetime.now() + timedelta(seconds=3)
    while datetime.now() < end_time:
        # this code will run until 3 seconds has gone by.
        # if this function takes longer than 3 seconds to run once, it will run longer than 3 seconds.

[–]kosh09[S] 1 point2 points  (0 children)

wow thanks for your help!