What is the proper way to call a method at a certain time (certain time here is a parameter)?
I need the timer, but is it necessary to represent incoming time and time.now()
in seconds to get and to use the difference between them?
The code:
import datetime, time
import threading
from threading import Timer
def doItThen():
print ("did it")
def launchTimer(dateAndTime):
dateTimeNow = datetime.datetime.now()
t = threading.Timer((dateAndTime-dateTimeNow).seconds, doItThen)
t.start()
if __name__ == "__main__":
launchTimer(datetime.datetime(2018, 2, 21, 8, 27, 51))
the result:
did it
(works)
but what are the risks in using this approach? im not good in testing or predicting the weeknesses