Rename a local variable for readability and change a "this can't

happen" print() call into a RuntimeWarning as it should've been in the
first place.  Because nothing should ever cause unexpected stdout output.
This commit is contained in:
Gregory P. Smith 2012-11-10 23:33:17 -08:00
parent 3d8e776cd9
commit f44c9da166
1 changed files with 8 additions and 6 deletions

View File

@ -1351,26 +1351,28 @@ class Popen(object):
# Wait for exec to fail or succeed; possibly raising an # Wait for exec to fail or succeed; possibly raising an
# exception (limited in size) # exception (limited in size)
data = bytearray() errpipe_data = bytearray()
while True: while True:
part = _eintr_retry_call(os.read, errpipe_read, 50000) part = _eintr_retry_call(os.read, errpipe_read, 50000)
data += part errpipe_data += part
if not part or len(data) > 50000: if not part or len(errpipe_data) > 50000:
break break
finally: finally:
# be sure the FD is closed no matter what # be sure the FD is closed no matter what
os.close(errpipe_read) os.close(errpipe_read)
if data: if errpipe_data:
try: try:
_eintr_retry_call(os.waitpid, self.pid, 0) _eintr_retry_call(os.waitpid, self.pid, 0)
except OSError as e: except OSError as e:
if e.errno != errno.ECHILD: if e.errno != errno.ECHILD:
raise raise
try: try:
exception_name, hex_errno, err_msg = data.split(b':', 2) exception_name, hex_errno, err_msg = (
errpipe_data.split(b':', 2))
except ValueError: except ValueError:
print('Bad exception data:', repr(data)) warnings.warn(RuntimeWarning(
'Bad exception data: %r' % errpipe_data))
exception_name = b'RuntimeError' exception_name = b'RuntimeError'
hex_errno = b'0' hex_errno = b'0'
err_msg = b'Unknown' err_msg = b'Unknown'