Bladeren bron

[siso] Propagte SIGINT to siso process

siso's signal handler doesn't run as expected with siso/autosiso
wrappers.
This CL sets signal handlers for the Python wrappers to propagate
signals to siso.

Note that Siso immediately exists at the 2nd Ctrl-C.
So developers can stop Siso forcibly when they want.

Bug: b/308734805
Change-Id: Idd8cc1d99931d609cfc3bedfb4c0bb4319cd20b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4996768
Reviewed-by: Fumitoshi Ukai <ukai@google.com>
Commit-Queue: Junji Watanabe <jwata@google.com>
Junji Watanabe 1 jaar geleden
bovenliggende
commit
9ed72f91a9
2 gewijzigde bestanden met toevoegingen van 9 en 9 verwijderingen
  1. 1 5
      autosiso.py
  2. 8 4
      siso.py

+ 1 - 5
autosiso.py

@@ -62,11 +62,7 @@ def main(argv):
             '-project=',
             '-project=',
             '-reapi_instance=',
             '-reapi_instance=',
         ] + argv[1:]
         ] + argv[1:]
-        try:
-            return siso.main(argv)
-        except KeyboardInterrupt:
-            print("Shutting down reproxy...", file=sys.stderr)
-            return 1
+        return siso.main(argv)
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':

+ 8 - 4
siso.py

@@ -8,6 +8,7 @@ binary when run inside a gclient source tree, so users can just type
 "siso" on the command line."""
 "siso" on the command line."""
 
 
 import os
 import os
+import signal
 import subprocess
 import subprocess
 import sys
 import sys
 
 
@@ -15,6 +16,12 @@ import gclient_paths
 
 
 
 
 def main(args):
 def main(args):
+    # Propagate signals to siso process so that it can run cleanup steps.
+    # Siso will be terminated immediately after the second Ctrl-C.
+    signal.signal(signal.SIGINT, lambda signum, frame: None)
+    if not sys.platform.startswith('win'):
+        signal.signal(signal.SIGTERM, lambda signum, frame: None)
+
     # On Windows the siso.bat script passes along the arguments enclosed in
     # On Windows the siso.bat script passes along the arguments enclosed in
     # double quotes. This prevents multiple levels of parsing of the special '^'
     # double quotes. This prevents multiple levels of parsing of the special '^'
     # characters needed when compiling a single file.  When this case is
     # characters needed when compiling a single file.  When this case is
@@ -80,7 +87,4 @@ def main(args):
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
-    try:
-        sys.exit(main(sys.argv))
-    except KeyboardInterrupt:
-        sys.exit(1)
+    sys.exit(main(sys.argv))