subprocess: Do extra work for error processing only for preexec_fn

This commit is contained in:
Yury Selivanov 2016-06-08 17:29:33 -04:00
parent b5b3b12dbb
commit 905bd8eea0
1 changed files with 8 additions and 7 deletions

View File

@ -90,12 +90,13 @@ cdef class UVProcess(UVHandle):
os_close(self._errpipe_write)
errpipe_data = bytearray()
while True:
part = os_read(self._errpipe_read, 50000)
errpipe_data += part
if not part or len(errpipe_data) > 50000:
break
if preexec_fn is not None:
errpipe_data = bytearray()
while True:
part = os_read(self._errpipe_read, 50000)
errpipe_data += part
if not part or len(errpipe_data) > 50000:
break
finally:
os_close(self._errpipe_read)
@ -121,7 +122,7 @@ cdef class UVProcess(UVHandle):
if debug_flags & __PROCESS_DEBUG_SLEEP_AFTER_FORK:
time_sleep(1)
if errpipe_data:
if preexec_fn is not None and errpipe_data:
# preexec_fn has raised an exception. The child
# process must be dead now.
try: