Python 如何在使用调度库调用函数时传递参数?

Python 如何在使用调度库调用函数时传递参数?,python,cron,schedule,Python,Cron,Schedule,我想知道是否有人可以帮助我在使用库调用job函数时如何传递参数。我看到在使用线程和run_threaded函数时,有两个相同的示例,但什么都没有 在下面的代码片段中,我试图将“sample_input”作为参数传递,但对如何定义此参数感到困惑 def run_threaded(job_func): job_thread = threading.Thread(target=job_func) job_thread.start() @with_logging def job(input_name)

我想知道是否有人可以帮助我在使用库调用job函数时如何传递参数。我看到在使用线程和run_threaded函数时,有两个相同的示例,但什么都没有

在下面的代码片段中,我试图将“sample_input”作为参数传递,但对如何定义此参数感到困惑

def run_threaded(job_func):
job_thread = threading.Thread(target=job_func)
job_thread.start()

@with_logging
def job(input_name):
    print("I'm running on thread %s" % threading.current_thread())
    main(input_name)

schedule.every(10).seconds.do(run_threaded, job(‘sample_input’))

您可以通过更改方法定义和调用类似于下面内容的签名来获得

# run_threaded method accepts arguments of job_func
def run_threaded(job_func, *args, **kwargs):
   print "======", args, kwargs
   job_thread = threading.Thread(target=job_func, args=args, kwargs=kwargs)
   job_thread.start()

# Invoke the arguments while scheduling.
schedule.every(10).seconds.do(run_threaded, job, "sample_input")