import os, time, threading
import schedule

def get_files():
    for root, directory, files in os.walk(os.getcwd()):
        for file in files:
            name, ext = os.path.splitext(file)
            if ext=='.py':
                ret = os.path.join(root, file)
                yield ret

def perform_command(py_file):
    os.system('python %s' % py_file)

def main():
    threads = []
    for file in get_files():
        if file.split('\\')[-1]!=os.path.basename(__file__):
            threads.append(threading.Thread(target=perform_command, args=(file,)))
    for thread in threads:
        thread.start()
    print('Done!', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))

if __name__ == '__main__':
    schedule.every().hour.do(main)#设置运行周期
    while True:
        schedule.run_pending()
        time.sleep(1)

 

posted on 2019-06-23 23:54  math98  阅读(298)  评论(0)    收藏  举报