From 905bd8eea029e768ef6ab899e04621dad8c43aa6 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Wed, 8 Jun 2016 17:29:33 -0400 Subject: [PATCH] subprocess: Do extra work for error processing only for preexec_fn --- uvloop/handles/process.pyx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/uvloop/handles/process.pyx b/uvloop/handles/process.pyx index 5c0a553..35363e2 100644 --- a/uvloop/handles/process.pyx +++ b/uvloop/handles/process.pyx @@ -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: