python subprocess 관련 질문입니다 .
조회수 387회
cmd1 = "sed 's/tmp_lig/" + output_file + "/g' runFR.sh > runFR_tmp_" + str(while_cnt) + "_" + str(compoundIdx) + ".sh"
proc = subprocess.call( cmd1 , shell=True)
cmd2 = "nohup bash runFR_tmp_" + str(while_cnt) + "_" + str(compoundIdx) + ".sh 1> ADRF.log 2>&1 &"
proc = subprocess.call( cmd2, shell=True)
#----find the minimum score of FR
fi = open('tmp_lig_' + str(while_cnt) + '_' + str(compoundIdx) + '_rigid_summary.dlg', 'r').readlines()
안녕하세요. 위와 같은 코드에서 subprocess.call을 이용하여 cmd2을 실행합니다. 여기서 제가 미리 짜논 bash script을 수행하고 되고 결과 파일을 열어 원하는 정보를 취하려고 합니다.
그런데 문제점은 계산이 먼저 끝나서 결과 파일이 먼저 나오면 상관 없지만, subprocess 특성상(?) 또 다른 shell을 실행하는 것이므로 계산이 끝나지 않았는데도 결과 파일을 읽으려는 코드 라인이 실행됩니다. 따라서 아래와 같은 오류가 발생하게 됩니다. fi = open('tmp_lig_' + str(while_cnt) + '_' + str(compoundIdx) + '_rigid_summary.dlg', 'r').readlines() IOError: [Errno 2] No such file or directory: 'tmp_lig_5_2_rigid_summary.dlg'
혹시 subprocess로 실행한 다른 shell의 동작이 끝나야 파이썬 script의 다음 라인을 실행하게 하는 방법이 있을까요?
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력