Periodic function execution

# Squares the next number (until 1000) every 3 seconds import sched from time import time, sleep def square(x): print(x*x) current_param, end_param = 0, 1000 current_delay, delay_interval = 0, 3 priority = 1 scheduler = sched.scheduler(time, sleep) while current_param < end_param: scheduler.enter(current_delay, priority, square, (current_param,)) current_param += 1 current_delay += delay_interval scheduler.run()