python:高级 python 调度程序 - cron 风格调度 - 传递函数参数
我正在尝试使用高级 python 调度程序来安排 con 风格的作业。每当我使用不需要任何参数的函数时,一切都很好,但是我无法安排传递一个或多个参数的同一作业。你能建议一下吗?
from apscheduler.scheduler import Scheduler
def job_def(var1, var2):
print "%s - %s" % (str(var1), str(var2))
s = Scheduler()
s.add_cron_job(job_def,['hello', 'there'], seconds='*/30')
s.start()
错误:
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler scheduler.py", line 346, in add_cron_job start_date=start_date)
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler/triggers/cron/__init__.py", line 44, in __init__ field = field_class(field_name, exprs, is_default)
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler/triggers/cron/fields.py", line 29, in __init__ self.compile_expressions(exprs)
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler/triggers/cron/fields.py", line 56, in compile_expressions self.compile_expression(expr)
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler/triggers/cron/fields.py", line 69, in compile_expression (expr, self.name))
I am trying to schedule con style job using advanced python scheduler. Everything is fine whenever I use function that does not require any parameters, however I am unable to schedule the same job passing one or more arguments. Could you please advise?
from apscheduler.scheduler import Scheduler
def job_def(var1, var2):
print "%s - %s" % (str(var1), str(var2))
s = Scheduler()
s.add_cron_job(job_def,['hello', 'there'], seconds='*/30')
s.start()
Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler scheduler.py", line 346, in add_cron_job start_date=start_date)
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler/triggers/cron/__init__.py", line 44, in __init__ field = field_class(field_name, exprs, is_default)
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler/triggers/cron/fields.py", line 29, in __init__ self.compile_expressions(exprs)
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler/triggers/cron/fields.py", line 56, in compile_expressions self.compile_expression(expr)
File "/usr/local/lib/python2.7/dist-packages/APScheduler-2.0.2-py2.7.egg/apscheduler/triggers/cron/fields.py", line 69, in compile_expression (expr, self.name))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,根据文档,它应该是
second= “*/30”
而不是seconds="*30/"
,然后,add_cron_job
方法原型是:所以,你的情况,你应该写这样的东西:
First, according to the documentation, it should be
second="*/30"
instead ofseconds="*30/"
, then, theadd_cron_job
method prototype is :so, in your case, you should write something like this :
使用起来不是更方便吗
代替?
Would it not be easier to use
instead?