diff options
Diffstat (limited to 'git/cmd.py')
-rw-r--r-- | git/cmd.py | 19 |
1 files changed, 6 insertions, 13 deletions
@@ -25,7 +25,6 @@ from subprocess import ( from .util import ( LazyMixin, stream_copy, - WaitGroup ) from .exc import ( GitCommandError, @@ -193,28 +192,22 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): else: # Oh ... probably we are on windows. select.select() can only handle sockets, we have files # The only reliable way to do this now is to use threads and wait for both to finish - def _handle_lines(fd, handler, wg): + def _handle_lines(fd, handler): for line in fd: line = line.decode(defenc) if line and handler: handler(line) - if wg: - wg.done() - # Since the finalizer is expected to wait, we don't have to introduce our own wait primitive - # NO: It's not enough unfortunately, and we will have to sync the threads - wg = WaitGroup() + threads = [] for fd, handler in zip((process.stdout, process.stderr), (stdout_handler, stderr_handler)): - wg.add(1) - t = threading.Thread(target=_handle_lines, args=(fd, handler, wg)) + t = threading.Thread(target=_handle_lines, args=(fd, handler)) t.setDaemon(True) t.start() + threads.append(t) - # NOTE: Just joining threads can possibly fail as there is a gap between .start() and when it's - # actually started, which could make the wait() call to just return because the thread is not yet - # active - wg.wait() + for t in threads: + t.join() # end return finalizer(process) |