1

Here is an example of the problem:

datetime.utcnow() is currently: 2015-02-18 22:31:00

There is way to make Python call a method or execute any action when datetime.utcnow() reaches 2015-02-18 22:35:00 ? I wanna do this without a loop to check if datetime.utcnow() reached 2015-02-18 22:35:00, just like a trigger.

Any suggestions?

thanks,

Johann Gomes
  • 3,813
  • 5
  • 23
  • 25

2 Answers2

3

If you want to do this asynchronously, you can use threading.Timer:

t = threading.Timer(secondsUntilDesiredTime, myFunction)
t.start()

However, the timer is not guaranteed to be exact.

rlbond
  • 65,341
  • 56
  • 178
  • 228
0

You can set a cronjob from python with the python-crontab module: python-crontab 1.9.2

That way you can trigger an action at that specific time.

Favo
  • 818
  • 6
  • 15