如何使用调度库调用函数时传递参数?
我想知道是否有人可以在使用schedule函数库调用工作函数时如何传递参数。我发现在使用线程和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") 
以上是 如何使用调度库调用函数时传递参数? 的全部内容, 来源链接: utcz.com/qa/265928.html

