避免使用shell子进程来启动cron作业,可以通过如下方式来实现:
#!/usr/bin/env python import time import subprocess
def check_and_start_job(): # Do some check to see if the job should run # If it should, execute the command subprocess.Popen(["/path/to/command"])
while True: check_and_start_job() time.sleep(60) # Check every minute