| OLD | NEW |
| 1 # Copyright (c) 2009, Google Inc. All rights reserved. | 1 # Copyright (c) 2009, Google Inc. All rights reserved. |
| 2 # Copyright (c) 2009 Apple Inc. All rights reserved. | 2 # Copyright (c) 2009 Apple Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 DEVNULL = open(os.devnull, 'wb') | 90 DEVNULL = open(os.devnull, 'wb') |
| 91 | 91 |
| 92 def _should_close_fds(self): | 92 def _should_close_fds(self): |
| 93 # We need to pass close_fds=True to work around Python bug #2320 | 93 # We need to pass close_fds=True to work around Python bug #2320 |
| 94 # (otherwise we can hang when we kill DumpRenderTree when we are running | 94 # (otherwise we can hang when we kill DumpRenderTree when we are running |
| 95 # multiple threads). See http://bugs.python.org/issue2320 . | 95 # multiple threads). See http://bugs.python.org/issue2320 . |
| 96 # Note that close_fds isn't supported on Windows, but this bug only | 96 # Note that close_fds isn't supported on Windows, but this bug only |
| 97 # shows up on Mac and Linux. | 97 # shows up on Mac and Linux. |
| 98 return sys.platform not in ('win32', 'cygwin') | 98 return sys.platform not in ('win32', 'cygwin') |
| 99 | 99 |
| 100 def _run_command_with_teed_output(self, args, teed_output, **kwargs): | |
| 101 child_process = self.popen(args, | |
| 102 stdout=self.PIPE, | |
| 103 stderr=self.STDOUT, | |
| 104 close_fds=self._should_close_fds(), | |
| 105 **kwargs) | |
| 106 | |
| 107 # Use our own custom wait loop because Popen ignores a tee'd | |
| 108 # stderr/stdout. | |
| 109 # FIXME: This could be improved not to flatten output to stdout. | |
| 110 while True: | |
| 111 output_line = child_process.stdout.readline() | |
| 112 if output_line == "" and child_process.poll() != None: | |
| 113 # poll() is not threadsafe and can throw OSError due to: | |
| 114 # http://bugs.python.org/issue1731717 | |
| 115 return child_process.poll() | |
| 116 # We assume that the child process wrote to us in utf-8, | |
| 117 # so no re-encoding is necessary before writing here. | |
| 118 teed_output.write(output_line) | |
| 119 | |
| 120 def cpu_count(self): | 100 def cpu_count(self): |
| 121 return multiprocessing.cpu_count() | 101 return multiprocessing.cpu_count() |
| 122 | 102 |
| 123 @staticmethod | 103 @staticmethod |
| 124 def interpreter_for_script(script_path, fs=None): | 104 def interpreter_for_script(script_path, fs=None): |
| 125 fs = fs or FileSystem() | 105 fs = fs or FileSystem() |
| 126 lines = fs.read_text_file(script_path).splitlines() | 106 lines = fs.read_text_file(script_path).splitlines() |
| 127 if not len(lines): | 107 if not len(lines): |
| 128 return None | 108 return None |
| 129 first_line = lines[0] | 109 first_line = lines[0] |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 pool.close() | 458 pool.close() |
| 479 pool.join() | 459 pool.join() |
| 480 | 460 |
| 481 | 461 |
| 482 def _run_command_thunk(cmd_line_and_cwd): | 462 def _run_command_thunk(cmd_line_and_cwd): |
| 483 # Note that this needs to be a bare module (and hence Picklable) method to w
ork with multiprocessing.Pool. | 463 # Note that this needs to be a bare module (and hence Picklable) method to w
ork with multiprocessing.Pool. |
| 484 (cmd_line, cwd) = cmd_line_and_cwd | 464 (cmd_line, cwd) = cmd_line_and_cwd |
| 485 proc = subprocess.Popen(cmd_line, cwd=cwd, stdout=subprocess.PIPE, stderr=su
bprocess.PIPE) | 465 proc = subprocess.Popen(cmd_line, cwd=cwd, stdout=subprocess.PIPE, stderr=su
bprocess.PIPE) |
| 486 stdout, stderr = proc.communicate() | 466 stdout, stderr = proc.communicate() |
| 487 return (proc.returncode, stdout, stderr) | 467 return (proc.returncode, stdout, stderr) |
| OLD | NEW |