From: Ben Darnell Date: Mon, 14 Nov 2011 02:07:32 +0000 (-0800) Subject: Add an option to the test runner to kill the process on SIGINT X-Git-Tag: v2.2.0~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89f35bc1cb4a2be177721d1ec6011137219e5159;p=thirdparty%2Ftornado.git Add an option to the test runner to kill the process on SIGINT instead of raising an exception. This makes it easier to work with tests that get into uninterruptible states (such as threading.Lock deadlocks) --- diff --git a/tornado/testing.py b/tornado/testing.py index 0ad5bff4c..bf49edf8b 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -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)