(context, timeout, args, **rest)
| 705 | |
| 706 | |
| 707 | def RunProcess(context, timeout, args, **rest): |
| 708 | if context.verbose: print("#", " ".join(args)) |
| 709 | popen_args = args |
| 710 | prev_error_mode = SEM_INVALID_VALUE |
| 711 | if utils.IsWindows(): |
| 712 | if context.suppress_dialogs: |
| 713 | # Try to change the error mode to avoid dialogs on fatal errors. Don't |
| 714 | # touch any existing error mode flags by merging the existing error mode. |
| 715 | # See http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx. |
| 716 | error_mode = SEM_NOGPFAULTERRORBOX |
| 717 | prev_error_mode = Win32SetErrorMode(error_mode) |
| 718 | Win32SetErrorMode(error_mode | prev_error_mode) |
| 719 | |
| 720 | process = subprocess.Popen( |
| 721 | args = popen_args, |
| 722 | **rest |
| 723 | ) |
| 724 | if utils.IsWindows() and context.suppress_dialogs and prev_error_mode != SEM_INVALID_VALUE: |
| 725 | Win32SetErrorMode(prev_error_mode) |
| 726 | # Compute the end time - if the process crosses this limit we |
| 727 | # consider it timed out. |
| 728 | if timeout is None: end_time = None |
| 729 | else: end_time = time.time() + timeout |
| 730 | timed_out = False |
| 731 | # Repeatedly check the exit code from the process in a |
| 732 | # loop and keep track of whether or not it times out. |
| 733 | exit_code = None |
| 734 | sleep_time = INITIAL_SLEEP_TIME |
| 735 | |
| 736 | while exit_code is None: |
| 737 | if (not end_time is None) and (time.time() >= end_time): |
| 738 | # Kill the process and wait for it to exit. |
| 739 | KillTimedOutProcess(context, process.pid) |
| 740 | exit_code = process.wait() |
| 741 | timed_out = True |
| 742 | else: |
| 743 | exit_code = process.poll() |
| 744 | time.sleep(sleep_time) |
| 745 | sleep_time = sleep_time * SLEEP_TIME_FACTOR |
| 746 | if sleep_time > MAX_SLEEP_TIME: |
| 747 | sleep_time = MAX_SLEEP_TIME |
| 748 | return (process, exit_code, timed_out) |
| 749 | |
| 750 | |
| 751 | def PrintError(str): |
no test coverage detected
searching dependent graphs…