Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: gclient_utils.py

Issue 3140013: Flush more often in gclient's SubprocessCallAndFilter.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2009 Google Inc. All Rights Reserved. 1 # Copyright 2009 Google Inc. All Rights Reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 print('\n________ running \'%s\' in \'%s\'' 272 print('\n________ running \'%s\' in \'%s\''
273 % (' '.join(command), in_directory)) 273 % (' '.join(command), in_directory))
274 274
275 # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for the 275 # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for the
276 # executable, but shell=True makes subprocess on Linux fail when it's called 276 # executable, but shell=True makes subprocess on Linux fail when it's called
277 # with a list because it only tries to execute the first item in the list. 277 # with a list because it only tries to execute the first item in the list.
278 kid = subprocess.Popen(command, bufsize=0, cwd=in_directory, 278 kid = subprocess.Popen(command, bufsize=0, cwd=in_directory,
279 shell=(sys.platform == 'win32'), stdout=subprocess.PIPE, 279 shell=(sys.platform == 'win32'), stdout=subprocess.PIPE,
280 stderr=subprocess.STDOUT) 280 stderr=subprocess.STDOUT)
281 281
282 # Do a flush of sys.stdout before we begin reading from the subprocess's
283 # stdout.
284 last_flushed_at = time.time()
285 sys.stdout.flush()
286
282 # Also, we need to forward stdout to prevent weird re-ordering of output. 287 # Also, we need to forward stdout to prevent weird re-ordering of output.
283 # This has to be done on a per byte basis to make sure it is not buffered: 288 # This has to be done on a per byte basis to make sure it is not buffered:
284 # normally buffering is done for each line, but if svn requests input, no 289 # normally buffering is done for each line, but if svn requests input, no
285 # end-of-line character is output after the prompt and it would not show up. 290 # end-of-line character is output after the prompt and it would not show up.
286 in_byte = kid.stdout.read(1) 291 in_byte = kid.stdout.read(1)
287 in_line = '' 292 in_line = ''
288 while in_byte: 293 while in_byte:
289 if in_byte != '\r': 294 if in_byte != '\r':
290 if print_stdout: 295 if print_stdout:
291 if not print_messages: 296 if not print_messages:
292 print('\n________ running \'%s\' in \'%s\'' 297 print('\n________ running \'%s\' in \'%s\''
293 % (' '.join(command), in_directory)) 298 % (' '.join(command), in_directory))
294 print_messages = True 299 print_messages = True
295 sys.stdout.write(in_byte) 300 sys.stdout.write(in_byte)
296 if in_byte != '\n': 301 if in_byte != '\n':
297 in_line += in_byte 302 in_line += in_byte
298 if in_byte == '\n' and filter_fn: 303 if in_byte == '\n':
299 filter_fn(in_line) 304 if filter_fn:
305 filter_fn(in_line)
300 in_line = '' 306 in_line = ''
307 # Flush at least 10 seconds between line writes. We wait at least 10
308 # seconds to avoid overloading the reader that called us with output,
309 # which can slow busy readers down.
310 if (time.time() - last_flushed_at) > 10:
311 last_flushed_at = time.time()
312 sys.stdout.flush()
301 in_byte = kid.stdout.read(1) 313 in_byte = kid.stdout.read(1)
302 rv = kid.wait() 314 rv = kid.wait()
303 315
304 if rv: 316 if rv:
305 msg = 'failed to run command: %s' % ' '.join(command) 317 msg = 'failed to run command: %s' % ' '.join(command)
306 318
307 if fail_status != None: 319 if fail_status != None:
308 print >>sys.stderr, msg 320 print >>sys.stderr, msg
309 sys.exit(fail_status) 321 sys.exit(fail_status)
310 322
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 self.lock.acquire() 475 self.lock.acquire()
464 assert not d.name in self.ran 476 assert not d.name in self.ran
465 if not d.name in self.ran: 477 if not d.name in self.ran:
466 self.ran.append(d.name) 478 self.ran.append(d.name)
467 self.running.remove(d) 479 self.running.remove(d)
468 if self.progress: 480 if self.progress:
469 self.progress.update(1) 481 self.progress.update(1)
470 finally: 482 finally:
471 self.lock.release() 483 self.lock.release()
472 return True 484 return True
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698