【发布时间】:2021-03-20 02:43:50
【问题描述】:
我正在尝试从 foo() 函数内部停止 while 循环的执行。我试过 exit() / sys.exit 没有成功。如何从函数内部完全停止程序的执行?
from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime, timedelta
import time
import sys
def foo(stop = False):
print('Function foo executed')
if stop:
sys.exit
scheduler = BackgroundScheduler()
dd = datetime.now() + timedelta(seconds=10)
scheduler.add_job(foo, 'date', run_date=dd, args=[True])
scheduler.start()
while True:
print('Inside the loop')
time.sleep(2)
【问题讨论】:
标签: python exit execution terminate apscheduler