import datetime,time,os from apscheduler.schedulers.blocking import BlockingScheduler def func0(): now = datetime.datetime.now() ts = now.strftime('%Y-%m-%d %H:%M:%S') print('do func time :',ts) def func1(): os.system('netsh interface set interface name="以太网" admin=DISABLED') def func2(): os.system('netsh interface set interface name="以太网" admin=ENABLED') def main(): #创建调度器:BlockingScheduler scheduler = BlockingScheduler() #添加任务 #scheduler.add_job(func0, 'interval', seconds=2, id='job0') #每天定时断网 scheduler.add_job(func1, 'cron', hour=20, minute=0, id='func1') #每天定时开网 scheduler.add_job(func2, 'cron', hour=8, minute=0, id='func2') scheduler.start() main()
可将脚本改为.pyw 后台运行。
标签:func2,断开,python,datetime,scheduler,interface,定时,id,def From: https://www.cnblogs.com/pu369/p/17672294.html