可用schedule 模块,不必造轮子
import time
import datetime
import threading
import types
class Crontab:
def __init__(self, job,max_thread_limit=20):
self.job = job
self.logfile = 'Crontab_log.txt'
self.thread_list = []
self.max_thread_limit = max_thread_limit
def check(self):
def exit_display():
exit("joblist like [ {'name':str,'crontab':str,'func':FunctionType,'args':tuple}, ... ]")
k = ['name', 'func', 'args', 'crontab']
for one in self.job:
for i in k:
if i not in one.keys():
exit_display()
if type(one['name']) is not str:
exit_display()
if type(one['crontab']) is not str:
exit_display()
if not isinstance(one['func'], types.FunctionType):
exit_display()
if type(one['args']) is not tuple:
exit_display()
return 0
def min_clock(self, s):
try:
if type(s) is not str:
print("params type is str...03 10 59")
while True:
tim = datetime.datetime.now().strftime('%H:%M:%S').split(":")
if tim[2] == s:
time.sleep(1)
return 0
else:
time.sleep(0.5)
pass
except Exception as e:
print("min_clocl_erro\n", e)
return -1
@staticm