Some perf imps

This commit is contained in:
Anthony Scopatz 2016-11-12 13:05:18 -05:00
parent e74a178a5f
commit c05e436281

View file

@ -600,23 +600,20 @@ class PopenThread(threading.Thread):
# loop over reads while process is running.
i = j = cnt = 1
while proc.poll() is None:
if not self.in_alt_mode:
if i + j == 0:
cnt = min(cnt + 1, 1000)
time.sleep(self.timeout * cnt)
else:
cnt = 1
# this is here for CPU performance reasons.
if i + j == 0:
cnt = min(cnt + 1, 1000)
procout.timeout = procerr.timeout = self.timeout * cnt
elif cnt == 1:
pass
else:
cnt = 1
procout.timeout = procerr.timeout = self.timeout
# redirect some output!
i = self._read_write(procout, stdout, sys.__stdout__)
j = self._read_write(procerr, stderr, sys.__stderr__)
if self.suspended:
break
elif self.in_alt_mode:
# this is here for CPU performance reasons.
if i + j == 0:
cnt = min(cnt + 1, 1000)
else:
cnt = 1
procout.timeout = procerr.timeout = self.timeout * cnt
if self.suspended:
return
# close files to send EOF to non-blocking reader.
@ -1703,6 +1700,7 @@ class CommandPipeline:
# read from process while it is running
check_prev_done = len(self.procs) == 1
prev_end_time = None
i = j = cnt = 1
while proc.poll() is None:
if getattr(proc, 'suspended', False):
return
@ -1720,9 +1718,13 @@ class CommandPipeline:
proc.prevs_are_closed = True
break
stdout_lines = safe_readlines(stdout, 1024)
yield from stdout_lines
i = len(stdout_lines)
if i != 0:
yield from stdout_lines
stderr_lines = safe_readlines(stderr, 1024)
self.stream_stderr(stderr_lines)
j = len(stderr_lines)
if j != 0:
self.stream_stderr(stderr_lines)
if not check_prev_done:
# if we are piping...
if (stdout_lines or stderr_lines):
@ -1739,7 +1741,12 @@ class CommandPipeline:
# next-to-last proc has finished, wait a bit to make
# sure we have fully started up, etc.
check_prev_done = True
time.sleep(timeout * 100)
# this is for CPU usage
if i + j == 0:
cnt = min(cnt + 1, 1000)
else:
cnt = 1
time.sleep(timeout * cnt)
# read from process now that it is over
yield from safe_readlines(stdout)
self.stream_stderr(safe_readlines(stderr))