많은 질문을 읽었으며 많은 것을 배웠습니다.하지만 여전히 문제를 해결할 수 없었습니다. C++ 실행 파일을 실행하고 실행 파일에서 stdout을 실시간으로 표시하는 wxPython 앱을 빌드하고 있습니다. 이 작품을 만들려고 몇 가지 이상한 결과가 나타났습니다. 나는 서브 프로세스를 완료하는 데 시간이 오래 걸리는 위의 코드를 실행하면이 할 수있는 모든 데이터와 출구를 쓰는 경우에도파이썬은 라인 단위로 서브 프로세스에서 stdout을 캡쳐합니다.
//test.cc (compiled as test.out with gcc 4.5.2)
#include <stdio.h>
int main()
{
FILE* fh = fopen("output.txt", "w");
for (int i = 0; i < 10000; i++)
{
printf("Outputting: %d\n", i);
fprintf(fh, "Outputting: %d\n", i);
}
fclose(fh);
return 0;
}
#wxPythonScript.py (running on 2.7 interpreter)
def run(self):
self.externalBinary = subprocess.Popen(['./test.out'], shell=False, stdout=subprocess.PIPE)
while not self.wantAbort:
line = self.externalBinary.stdout.readline()
wx.PostEvent(self.notifyWindow, Result_Event(line, Result_Event.EVT_STDOUT_ID))
print('Subprocess still running')
print('Subprocess aborted smoothly')
: 여기 내 현재 설정/문제입니다. 그러나 내가 실행하는 경우 매우 빠르게 완료된 다음 나는 PIPE에 서브 프로세스에서 표준 출력 리디렉션 때마다 다운/정지 속도가 느려 그래서 기본적으로
#wxPythonScript.py (running on 2.7 interpreter)
def run(self):
outFile = open('output.txt', 'r+')
self.externalBinary = subprocess.Popen(['./test.out'], shell=False, stdout=outFile)
while not self.wantAbort:
#line = self.externalBinary.stdout.readline()
#wx.PostEvent(self.notifyWindow, Result_Event(line, Result_Event.EVT_STDOUT_ID))
print('Subprocess still running')
print('Subprocess aborted smoothly')
을,하지만 난 파일에 기록하거나 리디렉션하지 않는 경우 그때는 괜찮습니다. 왜 그런가요?
을 (를) 검색하십시오. 이것은 자주 묻습니다. –
[read subprocess stdout line by line] 가능한 복제본 (0120)을 참조하십시오. –
약속 했어요. 나는 1 톤을 읽었다. 2 일 전 나는 서브 프로세스, 스레드, wx 이벤트, stdout에 대해 아무것도 몰랐습니다. 나는 물론 계속 찾고있을 것이다. 검색 할 키워드를 추천 해 주시겠습니까? 어쩌면 내가 잘못된 것을 찾고있을거야. 주로 검색했습니다 : stdout.readline python, subprocess stdout 등을 차단하지 않았습니다. – anderspitman