From 89f35bc1cb4a2be177721d1ec6011137219e5159 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 13 Nov 2011 18:07:32 -0800 Subject: [PATCH] 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) --- tornado/testing.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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) -- 2.47.3