From 2e7029116204cf2d6f516e4514091f0b492bc689 Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Tue, 1 Nov 2016 11:23:38 -0700 Subject: Make "git command" and "forall" work on Windows Python on Windows does not support non blocking file operations. To workaround this issue, we instead use Threads and a Queue to simulate non-blocking calls. This is happens only when running with the native Windows version of Python, meaning Linux and Cygwin are not affected by this change. Change-Id: I4ce23827b096c5138f67a85c721f58a12279bb6f --- subcmds/forall.py | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'subcmds/forall.py') diff --git a/subcmds/forall.py b/subcmds/forall.py index 07ee8d58..2c12c55f 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py @@ -15,17 +15,16 @@ from __future__ import print_function import errno -import fcntl import multiprocessing import re import os -import select import signal import sys import subprocess from color import Coloring from command import Command, MirrorSafeCommand +import platform_utils _CAN_COLOR = [ 'branch', @@ -344,35 +343,25 @@ def DoWork(project, mirror, opt, cmd, shell, cnt, config): if opt.project_header: out = ForallColoring(config) out.redirect(sys.stdout) - class sfd(object): - def __init__(self, fd, dest): - self.fd = fd - self.dest = dest - def fileno(self): - return self.fd.fileno() - empty = True errbuf = '' p.stdin.close() - s_in = [sfd(p.stdout, sys.stdout), - sfd(p.stderr, sys.stderr)] - - for s in s_in: - flags = fcntl.fcntl(s.fd, fcntl.F_GETFL) - fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) + s_in = platform_utils.FileDescriptorStreams.create() + s_in.add(p.stdout, sys.stdout, 'stdout') + s_in.add(p.stderr, sys.stderr, 'stderr') - while s_in: - in_ready, _out_ready, _err_ready = select.select(s_in, [], []) + while not s_in.is_done: + in_ready = s_in.select() for s in in_ready: - buf = s.fd.read(4096) + buf = s.read() if not buf: - s.fd.close() + s.close() s_in.remove(s) continue if not opt.verbose: - if s.fd != p.stdout: + if s.std_name == 'stderr': errbuf += buf continue -- cgit v1.2.3-54-g00ecf