Skip to content

Commit

Permalink
apveyor, gitpython-developers#519: FIX incomplete Popen pump
Browse files Browse the repository at this point in the history
+ Pump once, so when input larger than `mmap.PAGESIZE`, stream is not
emptied.
  • Loading branch information
ankostis committed Sep 25, 2016
1 parent d12fdca commit 040f549
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 9 additions & 8 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ def _parse_lines_from_buffer(buf):
# end

def _read_lines_from_fno(fno, last_buf_list):
buf = os.read(fno, mmap.PAGESIZE)
buf = last_buf_list[0] + buf
for buf in iter(lambda: os.read(fno, mmap.PAGESIZE), ''):
buf = last_buf_list[0] + buf

bi = 0
for bi, line in _parse_lines_from_buffer(buf):
yield line
# for each line to parse from the buffer
bi = 0
for bi, line in _parse_lines_from_buffer(buf):
yield line
# for each line to parse from the buffer

# keep remainder
last_buf_list[0] = buf[bi:]
# keep remainder
last_buf_list[0] = buf[bi:]

def _dispatch_single_line(line, handler):
line = line.decode(defenc)
Expand Down Expand Up @@ -199,6 +199,7 @@ def _deplete_buffer(fno, handler, buf_list, wg=None):
for fno, (handler, buf_list) in fdmap.items():
wg.add(1)
t = threading.Thread(target=lambda: _deplete_buffer(fno, handler, buf_list, wg))
t.setDaemon(True)
t.start()
# end
# NOTE: Just joining threads can possibly fail as there is a gap between .start() and when it's
Expand Down
4 changes: 3 additions & 1 deletion git/test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ def counter_stderr(line):
stdin=None,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
shell=False,
creationflags=Git.CREATE_NO_WINDOW if sys.platform == 'win32' else 0,
)

handle_process_output(proc, counter_stdout, counter_stderr, lambda proc: proc.wait())

Expand Down

0 comments on commit 040f549

Please sign in to comment.