아래의 예제 코드에서는 sandbox.log에 파일 설명자를 열고 하위 프로세스에 stdout으로 제공 한 다음 파일 설명자를 닫지 만 하위 프로세스는 여전히 파일에 쓸 수 있습니다. subprocess.Popen은 파일 설명자를 내부적으로 복제합니까? 파일 디스크립터를 서브 프로세스에 전달한 후에 파일 디스크립터를 닫는 것이 안전합니까?닫힌 파일 설명자는 어떻게됩니까?
% python test_close_fd.py
create or clear sandbox.log
open the file descriptor
run the command
fd is already closed
p isnt finished, but fd is closed
p just finished
Traceback (most recent call last):
File "test_close_fd.py", line 34, in <module>
raise Exception("There's text in sandbox.log. Whats going on?")
Exception: There's text in sandbox.log. Whats going on?
파이썬 2를 사용하고 있습니다. 'popen'의'close_fds' 매개 변수를보십시오. 이러한 이유로 3.2가 기본값으로 변경되었습니다. – cdarke