다른 Python 스크립트를 실행하기 위해 작성하고있는 Python 스크립트가 있습니다. 목표는 밤새 내 다른 스크립트를 실행하기 위해 항상 실행하는 스크립트를 가질 수있게하는 것입니다. (배치 파일을 사용하여이 파일을 시도했지만 파일을 실행했지만 어떤 이유로 든 .csv 파일을 만들지 못했습니다.) 이제는 지금 가지고있는 코드가 있습니다.다른 Python 스크립트를 실행하는 Python 스크립트
import time
import subprocess
from threading import Timer
fileRan = False
#Function to launch other python files
def runFiles():
print('Running Scripts Now')
subprocess.call("cmd","report1.py",shell=True)
subprocess.call("cmd","report2.py",shell=True)
subprocess.call("cmd","report3.py",shell=True)
subprocess.call("cmd","report4.py",shell=True)
subprocess.call("cmd","report5.py",shell=True)
subprocess.call("cmd","report6.py",shell=True)
#Function to check current system time against time reports should run
def checkTime(fileRan):
startTime = '15:20'
endTime = '15:25'
print('Current Time Is: ', time.strftime('%H:%M', time.localtime()))
print(fileRan)
if startTime < time.strftime('%H:%M', time.localtime()) < endTime and fileRan is False:
runFiles()
fileRan = True
return fileRan
#Timer itself
t = Timer(60.0, checkTime(fileRan))
t.start()
첫 번째 단계는 현재 시간을 인쇄하고 fileRan의 상태는 정상적으로 인쇄됩니다. 두 번째 검사를 할 때 또는 파일을 실행하려고 시도 할 때 파손 된 것처럼 보입니다. 내가 얻는 오류는 다음과 같습니다.
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python34\lib\threading.py", line 921, in _bootstrap_inner
self.run()
File "C:\Python34\lib\threading.py", line 1187, in run
self.function(*self.args, **self.kwargs)
TypeError: 'NoneType' object is not callable
도움이된다면 도움이 될 것입니다.
처음에는't = Timer (60.0, checkTime (fileRan))'을't = Timer (60.0, checkTime, fileRan)'으로 변경하십시오 (타이머는 함수 자체를 호출해야하므로, 함수를 호출 한 다음 결과를 전달) –
제안 된대로 변경했습니다. 't = Timer (60.0, checkTime, fileRan)'이제이 오류가 발생합니다. 'TypeError : * 이후의 checkTime() 인수는 * bool이 아닌 시퀀스 여야합니다. ' – user1971240
't = Timer (60.0, checkTime, [fileRan])'을 시도하고 내 대답도 편집하십시오. –