我们在平时的工作中经常会遇到这样的需求,需要再某个时间点执行一段程序逻辑。

那么,在python中我们是怎么做的呢?

下面看代码:

waitDesignatedTimeToRun.py

import time, datetime

startTime = datetime.datetime(2016, 6, 8, 16, 45, 0)
print('Program not starting yet...')
while datetime.datetime.now() < startTime:
    time.sleep(1)
print('Program now starts on %s' % startTime)
print('Executing...')

运行该小脚本,结果如下:

Program not starting yet...

(这里程序等待到制定时间)
Program now starts on 2016-06-08 16:45:00
Executing...

 

相关文章:

  • 2022-01-31
  • 2021-12-01
  • 2021-05-22
  • 2021-08-28
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-11
  • 2021-05-28
  • 2021-05-23
  • 2021-09-04
相关资源
相似解决方案