Reputation: 21
Using the following to set a 30 second break every 60 seconds, however I do not want the break to start as soon as the script is first run. How can I add an initial delay to the first break?
def Breaktime():
threading.Timer(60, Breaktime).start()
print("Breaking for 30 seconds")
time.sleep(30)
Breaktime()
Upvotes: 1
Views: 981
Reputation: 132138
How about passing an argument? Here is one way to do it.
def Breaktime(break_time=0):
threading.Timer(60, Breaktime, kwargs={"break_time": 30}).start()
print("Breaking for 30 seconds")
time.sleep(break_time)
Breaktime()
Upvotes: 1