다중 처리 프로세스가 시작될 플라스크 응용 프로그램을 배포하고 있습니다. 이 프로세스 내에서 쉘 명령 물마루 subprocess.call()을 호출합니다. 여기 배포 된 웹 응용 프로그램에서 셸 명령을 호출 할 때 예기치 않은 동작이 발생했습니다.
DEBUG:root:start to run command
DEBUG:root:(<class 'FileNotFoundError'>, FileNotFoundError(2, "No such file or directory: 'java -jar ábsolute/path/to/jar/file')
Process(
target=decode_upload,
args=(
path_to_blf,
path_to_dbc_folder,
path_to_splitted,
path_to_decoder,
system_layout,
dc_doc,
dc_id,
file_type,
)
).start()
가의 rellevant 일부입니다 nginx를하고 gunicorn 함께 배포 로컬 호스트에 실행될 때 스크립트는 잘 실행, 플라스크 앱이 하위 프로세스가 시작 예상대로 다르게 동작 할 때까지, 나는 다음과 같은 오류 로그를받을 기능.
def decode_file(
path_to_blf,
path_to_dbc_folder,
path_to_splitted,
path_to_decoder,
system_layout=DEFAULT_SYSTEM_LAYOUT):
command = "{} {} --blf={}".format(
SOFTWARE_COMMAND,
path_to_decoder,
path_to_blf
)
for dbc_file_name in DBC_FILE_NAME_LIST:
command += " --dbc={}".format(
os.path.join(
path_to_dbc_folder,
dbc_file_name
)
)
command += " --out={}".format(path_to_splitted)
logging.debug("start to run command")
subprocess.call(command)
logging.debug(f)
logging.debug("run command end")
def decode_upload(
path_to_blf,
path_to_dbc_folder,
path_to_splitted,
path_to_decoder,
system_layout,
dc_doc,
dc_id,
file_type):
logging.basicConfig(filename='flask.log',level=logging.DEBUG)
logging.debug('This message should go to the log file')
try:
decode_file(
path_to_blf,
path_to_dbc_folder,
path_to_splitted,
path_to_decoder,
system_layout)
except:
logging.debug(sys.exc_info())
이 줄에 도달하면 프로세스가 실패합니다.
subprocess.call(command)
명령 줄에서 "명령"을 호출하려고하면 문제없이 작동합니다.
안녕, 대답에 대한 감사 구하십시오. 예, 오류가 사라지 긴하지만 명령은 여전히 실행되지 않습니다. 나는이 명령에서 p = subprocess.run ("ls", shell = True, stdout = PIPE), logging.debug (p.stdout)를 사용하여 stdout을 잡았다. 로그 파일에 아무 것도 의미하지 않는 DEBUG : root : b " '라는 메시지가 나타납니다. 명령이 실행되지 않은 것으로 보입니다 –
지금 얻고있는 오류는 무엇입니까 –
아니요 더 이상 오류가 없습니다. os.system (명령)을 시도했지만 아무 일도 일어나지 않지만 터미널에서 명령을 실행하면 완벽하게 작동합니다. –