except ImportError: import _thread as thread # py3 from tornado.escape import utf8 from tornado import gen from tornado.httpclient import AsyncHTTPClient from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop from tornado.platform.auto import set_close_exec from tornado.platform.select import SelectIOLoop from tornado.testing import bind_unused_port from tornado.test.util import unittest from tornado.util import import_object from tornado.web import RequestHandler, Application skipIfNoTwisted = unittest.skipUnless(have_twisted, "twisted module not present") skipIfPy26 = unittest.skipIf(sys.version_info < (2, 7), "twisted incompatible with singledispatch in py26") def save_signal_handlers(): saved = {} for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGCHLD]: saved[sig] = signal.getsignal(sig) if "twisted" in repr(saved): if not issubclass(IOLoop.configured_class(), TwistedIOLoop): # when the global ioloop is twisted, we expect the signal # handlers to be installed. Otherwise, it means we're not # cleaning up after twisted properly. raise Exception("twisted signal handlers already installed") return saved
from tornado.platform.twisted import TornadoReactor from zope.interface import implementer have_twisted = True except ImportError: have_twisted = False from tornado.httpclient import AsyncHTTPClient from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop from tornado.platform.auto import set_close_exec from tornado.testing import bind_unused_port from tornado.test.util import unittest from tornado.util import import_object from tornado.web import RequestHandler, Application skipIfNoTwisted = unittest.skipUnless(have_twisted, "twisted module not present") def save_signal_handlers(): saved = {} for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGCHLD]: saved[sig] = signal.getsignal(sig) if "twisted" in repr(saved): raise Exception("twisted signal handlers already installed") return saved def restore_signal_handlers(saved): for sig, handler in saved.iteritems(): signal.signal(sig, handler)