Commit 873c28d1 authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

Capture ctrl-c in presubmit multiprocessing pool

Presubmit spins up lots of multiprocessing processes to run
each individual test. If you cancel your presubmit run with
<ctrl>+c, that signal gets passed through to each of those,
which then raises its own KeyboardInterrupt, and prints its
own stacktrace.

This change has each member of the multiprocessing pool instead
exit gracefully (albeit with an error code) so that only the
parent process prints its stacktrace.

R=michaelpg@chromium.org

Bug: 635196
Change-Id: If9081910a359889a43bc1b72c91a859ebe37a1d6
Reviewed-on: https://chromium-review.googlesource.com/651764Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
parent 5a4ef453
......@@ -30,6 +30,7 @@ import os # Somewhat exposed through the API.
import pickle # Exposed through the API.
import random
import re # Exposed through the API.
import signal
import sys # Parts exposed through API.
import tempfile # Exposed through the API.
import time
......@@ -435,11 +436,19 @@ class InputApi(object):
self.cpu_count = multiprocessing.cpu_count()
# this is done here because in RunTests, the current working directory has
# We initialize here because in RunTests, the current working directory has
# changed, which causes Pool() to explode fantastically when run on windows
# (because it tries to load the __main__ module, which imports lots of
# things relative to the current working directory).
self._run_tests_pool = multiprocessing.Pool(self.cpu_count)
# We capture ctrl-c in the initializer to prevent massive console spew when
# cancelling all of the processes with ctrl-c.
def _capture_interrupt():
CTRL_C = signal.SIGINT
if sys.platform == 'win32':
CTRL_C = signal.CTRL_C_EVENT
signal.signal(CTRL_C, lambda x, y: sys.exit(1))
self._run_tests_pool = multiprocessing.Pool(
self.cpu_count, _capture_interrupt)
# The local path of the currently-being-processed presubmit script.
self._current_presubmit_path = os.path.dirname(presubmit_path)
......
......@@ -165,8 +165,8 @@ class PresubmitUnittest(PresubmitTestsBase):
'git_footers', 'glob', 'inspect', 'json', 'load_files', 'logging',
'marshal', 'normpath', 'optparse', 'os', 'owners', 'owners_finder',
'pickle', 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm',
'subprocess', 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest',
'urllib2', 'warn', 'multiprocessing', 'DoGetTryMasters',
'signal', 'subprocess', 'sys', 'tempfile', 'time', 'traceback', 'types',
'unittest', 'urllib2', 'warn', 'multiprocessing', 'DoGetTryMasters',
'GetTryMastersExecuter', 'itertools', 'urlparse', 'gerrit_util',
'GerritAccessor',
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment