SoFunction
Updated on 2025-03-02

Detailed explanation of Python3 timer task code

A timer task demo written using threading:

import time
import sys
import signal
import datetime
import threading
#Timerdef schedule_update():
  t = (0, event_func)
  (True)
  ()
#Execute functiondef event_func():
  now_time = ().strftime('%Y-%m-%d %H:%M:%S')
  print(now_time)
  exec_update()
  #update_openvas_dbs_from_cache()
  interval_time = delay_time()
  t = (interval_time, event_func)
  (True)
  ()
#Take the time pointdef delay_time():
  # now time
  now_time = ()
  # tomorrow time
  next_time = now_time + (days=+1)
  next_year = next_time.date().year
  next_month = next_time.date().month
  next_day = next_time.date().day
  # get tomorrow 00:00
  next_time = (str(next_year)+"-"+str(next_month)+"-"+str(next_day)+" 00:00:00", "%Y-%m-%d %H:%M:%S")
  # get secondes
  delay_time = (next_time - now_time).total_seconds()
  return delay_time
def quit_sys(signum, frame):
  ()
#Receive Cif __name__ == "__main__":
  try:
    (, quit_sys)
    (, quit_sys)
    schedule_update()
    print("schedule_update server starting up...\nHit Ctrl-C to quit.\n")
    while 1:
      (1)
  except Exception as e:
    print(e)

Summarize

The above is the Python 3 timer task code introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!
If you think this article is helpful to you, please reprint it. Please indicate the source, thank you!