TypeError: the first argument must be callable

后端 未结 2 393
天涯浪人
天涯浪人 2021-02-06 04:38

I am using python and schedule lib to create a cron-like job

class MyClass:

        def local(self, command):
                #return subprocess.call(command, s         


        
相关标签:
2条回答
  • 2021-02-06 04:44

    replace

    schedule.every(1).minutes.do(self.local(script_path))
    

    with this one:

    schedule.every(1).minutes.do(self.local,script_path)
    

    and it will work fine..

    you should write the parameters of function after function name and comma separate them..

    0 讨论(0)
  • 2021-02-06 05:10

    do expects a callable and any arguments it make take.

    Therefore your call to do should look like:

    schedule.every(1).minutes.do(self.local, script_path)
    

    The do implementation can be found here.

    def do(self, job_func, *args, **kwargs):
        """Specifies the job_func that should be called every time the
        job runs.
    
        Any additional arguments are passed on to job_func when
        the job runs.
        """
        self.job_func = functools.partial(job_func, *args, **kwargs)
        functools.update_wrapper(self.job_func, job_func)
        self._schedule_next_run()
        return self
    
    0 讨论(0)
提交回复
热议问题