[PATCH] LIT: Support cancellation on Windows

Nico Rieck nico.rieck at gmail.com
Wed Jul 17 15:30:29 PDT 2013


The current machinery using KeyboardInterrupt for canceling doesn't work with multiple threads on Windows as it just cancels the current test but the main runner continues.

This patch installs a handler for Ctrl-C to stop the provider from providing any more tests.

http://llvm-reviews.chandlerc.com/D1172

Files:
  utils/lit/lit/main.py

Index: utils/lit/lit/main.py
===================================================================
--- utils/lit/lit/main.py
+++ utils/lit/lit/main.py
@@ -76,6 +76,12 @@
         self.iter = iter(tests)
         self.lock = threading.Lock()
         self.startTime = time.time()
+        self.canceled = False
+
+    def cancel(self):
+        self.lock.acquire()
+        self.canceled = True
+        self.lock.release()
 
     def get(self):
         # Check if we have run out of time.
@@ -85,6 +91,10 @@
 
         # Otherwise take the next test.
         self.lock.acquire()
+        if self.canceled:
+          self.lock.release()
+          return None
+
         try:
             item = self.iter.next()
         except StopIteration:
@@ -346,6 +356,16 @@
     startTime = time.time()
     display = TestingProgressDisplay(opts, len(tests), progressBar)
     provider = TestProvider(tests, opts.maxTime)
+
+    try:
+      import win32api
+      def console_ctrl_handler(type):
+        provider.cancel()
+        return True
+      win32api.SetConsoleCtrlHandler(console_ctrl_handler, True)
+    except ImportError:
+      pass
+
     runTests(opts.numThreads, litConfig, provider, display)
     display.finish()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1172.1.patch
Type: text/x-patch
Size: 1225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130717/695b899b/attachment.bin>


More information about the llvm-commits mailing list