2017-12-27 38 views
0

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’)) 

답변

1

메소드 정의를 변경하고 시그니처를 아래에서 비슷한 방법으로 호출하여 얻을 수 있습니다.

# 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")