Commit 9a5bb612 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

git-cl: Make Ctrl+C work again.

Bug: 961724
Change-Id: I4fc8f86c02fb53310c5967284594ba1fbbbcbafc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1826054
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@google.com>
parent f0faf48d
......@@ -90,11 +90,8 @@ class CommandData(object):
# Before a SIGINT is seen, wait(p) will simply call p.wait() and
# return the result. Once a SIGINT has been seen (in the main process
# or a subprocess, including the one the current call is waiting for),
# wait(p) will call p.terminate() and raise ProcessWasInterrupted.
# wait(p) will call p.terminate().
class SigintHandler(object):
class ProcessWasInterrupted(Exception):
pass
sigint_returncodes = {-signal.SIGINT, # Unix
-1073741510, # Windows
}
......@@ -102,7 +99,7 @@ class SigintHandler(object):
self.__lock = threading.Lock()
self.__processes = set()
self.__got_sigint = False
signal.signal(signal.SIGINT, lambda signal_num, frame: self.interrupt())
self.__previous_signal = signal.signal(signal.SIGINT, self.interrupt)
def __on_sigint(self):
self.__got_sigint = True
......@@ -112,9 +109,10 @@ class SigintHandler(object):
except OSError:
pass
def interrupt(self):
def interrupt(self, signal_num, frame):
with self.__lock:
self.__on_sigint()
self.__previous_signal(signal_num, frame)
def got_sigint(self):
with self.__lock:
......@@ -131,8 +129,6 @@ class SigintHandler(object):
self.__processes.discard(p)
if code in self.sigint_returncodes:
self.__on_sigint()
if self.__got_sigint:
raise self.ProcessWasInterrupted
return stdout, stderr
sigint_handler = SigintHandler()
......
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