gpt4 book ai didi

python - kwargs/args 错误。将参数传递给 apscheduler 处理函数

转载 作者:行者123 更新时间:2023-12-05 02:10:11 24 4
gpt4 key购买 nike

passing parameters to apscheduler handler function这对我不起作用,我尝试了不同的语法变体(见下文)。我可能遗漏了一些更基本的东西。

@app.route("/tick", methods=['GET', 'POST'])
def tick(datetimes, texti):
flash('DO! Sir, you have planned on the {} this:'.format(datetimes), 'success')
flash(texti, 'info')
return redirect(url_for('td_list'))

def Schedule_reminders():
with app.test_request_context():
if os.environ.get("WERKZEUG_RUN_MAIN") == "true":
# https://stackoverflow.com/questions/9449101/how-to-stop-flask-from-initialising-twice-in-debug-mode
scheduler = BackgroundScheduler()
tds = Td.query.all()
for td in tds:
run_date = td.date +' '+ td.time +':00'
# https://stackoverflow.com/questions/12412708/passing-parameters-to-apscheduler-handler-function/39027779#39027779
datetimes = run_date
texti = td.text
#scheduler.add_job(tick, 'date', [datetimes, texti], run_date)
# ValueError: dictionary update sequence element #0 has length 1; 2 is required

#scheduler.add_job(lambda: tick(datetimes, texti), 'date', run_date)
# ValueError: The list of positional arguments is longer than the target callable can handle (allowed: 0, given in args: 19)

#scheduler.add_job(tick, 'date', run_date, kwargs={'datetimes':run_date, 'texti':td.text})
# ValueError: The following arguments are supplied in both args and kwargs: datetimes, texti
#scheduler.add_job(print_date_time, 'date', run_date)

scheduler.start()

最佳答案

我认为我已经通过以某种方式重写 tick() 解决了这个问题:

def tick(*args):
flash('DO! Sir, you have planned on the {} this:'.format(args[0]), 'success')
texti = args[1]
flash(texti, 'info')

和 add_job:

 scheduler.add_job(tick, trigger='date', next_run_time=run_date, args=(run_date, td.text))

关于python - kwargs/args 错误。将参数传递给 apscheduler 处理函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59103756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com