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/651764
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
changes/64/651764/2
Aaron Gable 8 years ago committed by Commit Bot
parent 5a4ef4537e
commit 873c28d175

@ -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',
]

Loading…
Cancel
Save