Python中文
首页
教程
问答
标签
搜索
登录
注册
如何从apscheduler访问返回值?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我不太清楚如何在apscheduler中访问调度作业的返回值。作业需要在每天不同的时间运行,我需要今天作业的返回值来安排明天的作业。在</p> <p>这个链接(<a href="https://stackoverflow.com/questions/47707997/how-to-get-return-value-from-apscheduler-jobs">how to get return value from apscheduler jobs</a>)似乎是这个问题之前最好的答案。它建议在调度程序中添加一个侦听器。我添加了一个侦听器,但不确定如何访问它的返回值。我可以访问附加到调度程序的侦听器,但不能访问它们的输出。当计划作业运行时,将打印下面代码中的job_nses()侦听器。在</p> <p>此外,我知道我需要访问JobExecutionEvent(<a href="https://apscheduler.readthedocs.io/en/latest/modules/events.html#module-apscheduler.events" rel="nofollow noreferrer">https://apscheduler.readthedocs.io/en/latest/modules/events.html#module-apscheduler.events</a>),它保存函数的返回值。在</p> <p>首先,我要访问的函数是run_all(),其中执行了一系列操作,但是对于测试用例,我只返回True。在</p> <pre class="lang-py prettyprint-override"><code>from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.blocking import BlockingScheduler from apscheduler.events import EVENT_JOB_EXECUTED, EVENT_JOB_ERROR, JobExecutionEvent from datetime import datetime, timedelta import logging def run_all(): return True def job_runs(event): # listener function if event.exception: print('The job did not run') else: print('The job completed @ {}'.format(datetime.now())) def job_return_val(event): # listener function return event.retval </code></pre> <p>然后,我设置调度程序,添加侦听器,并添加作业。触发器设置为在作业添加到调度程序后1分钟运行函数。在</p> ^{pr2}$ <p>接下来,我启动调度程序并打印计划的作业。另外,我设置了日志记录,以便知道调度程序在哪里。在</p> <pre class="lang-py prettyprint-override"><code> test = scheduler.start() scheduler.print_jobs() logging.basicConfig() logging.getLogger('apscheduler').setLevel(logging.DEBUG) </code></pre> <p>启用日志记录后,调度程序报告作业已运行并从调度程序中删除,正如我所期望的那样。job_nses()将正确的输出打印到控制台。对于断点,我知道job\u return_val()被调用。但是,我不知道它返回的值被发送到哪里。该函数似乎是在另一个名为APScheduler的线程中调用的。我不太了解线程,但这是有道理的。但是,我不知道该线程的输出何时返回到主线程。在</p> <p>最后,我尝试用代码、job-id、jobstore和scheduled-run-time从scheduler和job的属性访问JobExceptionEvent,但是JobExceptionEvent似乎不知道事件是在scheduler中运行的。由于上一段中描述的线程,这似乎也有意义。在</p> 任何帮助整理这个问题太好了!在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您需要的是实现<a href="https://github.com/agronholm/apscheduler/issues/265" rel="nofollow noreferrer">stateful jobs feature</a>。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
jupyter运行一个旧的pytorch版本
3 回答
Jupyter运行不同版本的卸载库?
6 回答
Jupyter运行指定的键盘快捷键
1 回答
Jupyter通过.local文件“逃逸”virtualenv。我该如何缓解这种情况?
3 回答
Jupyter重新加载自定义样式
3 回答
Jupyter错误:“没有名为Jupyter_core.paths的模块”
9 回答
jupyter错误:无法在随机林中将决策树视为png
8 回答
Jupyter错误'内核似乎已经死亡,它将自动重新启动'为一个给定的代码块
4 回答
Jupyter错误地用阿拉伯语和字母数字元素显示Python列表
10 回答
Jupyter隐藏数据帧索引,但保留原始样式
10 回答
Jupyter集线器:启动器中出现致命错误。。。系统找不到指定的文件
1 回答
Jupyther中相同值的相同哈希,但导出到Bigquery时不相同
9 回答
Jupy上Python的读/写访问问题
6 回答
jupy上没有模块cv
7 回答
Jupy上的排序错误
10 回答
Jupy中bqplot图形的紧凑布局
2 回答
Jupy中matplotlib plot的连续更新
9 回答
Jupy中Numpy函数的文档
2 回答
Jupy中Pandas的自动完成问题
3 回答
jupy中Qt后端的Matplotlib动画
5 回答