]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add an option to the test runner to kill the process on SIGINT
authorBen Darnell <ben@bendarnell.com>
Mon, 14 Nov 2011 02:07:32 +0000 (18:07 -0800)
committerBen Darnell <ben@bendarnell.com>
Mon, 14 Nov 2011 02:07:32 +0000 (18:07 -0800)
instead of raising an exception.

This makes it easier to work with tests that get into uninterruptible
states (such as threading.Lock deadlocks)

tornado/testing.py

index 0ad5bff4cd3c7c12de9cfd4f064f988da3f4c0cd..bf49edf8b0db1f89af46aa602cbdd905ab510841 100644 (file)
@@ -26,6 +26,7 @@ from tornado.httpserver import HTTPServer
 from tornado.stack_context import StackContext, NullContext
 import contextlib
 import logging
+import signal
 import sys
 import time
 import unittest
@@ -325,12 +326,20 @@ def main():
     define('autoreload', type=bool, default=False,
            help="DEPRECATED: use tornado.autoreload.main instead")
     define('httpclient', type=str, default=None)
+    define('exception_on_interrupt', type=bool, default=True,
+           help=("If true (default), ctrl-c raises a KeyboardInterrupt "
+                 "exception.  This prints a stack trace but cannot interrupt "
+                 "certain operations.  If false, the process is more reliably "
+                 "killed, but does not print a stack trace."))
     argv = [sys.argv[0]] + parse_command_line(sys.argv)
 
     if options.httpclient:
         from tornado.httpclient import AsyncHTTPClient
         AsyncHTTPClient.configure(options.httpclient)
 
+    if not options.exception_on_interrupt:
+        signal.signal(signal.SIGINT, signal.SIG_DFL)
+
     if __name__ == '__main__' and len(argv) == 1:
         print >> sys.stderr, "No tests specified"
         sys.exit(1)