From: Ben Darnell Date: Sat, 25 Jan 2014 22:16:17 +0000 (-0500) Subject: Raise an error if IOLoop.start() is called while it is already running. X-Git-Tag: v4.0.0b1~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=869fb744db6402c4f6d65ec77249de1cb358af5e;p=thirdparty%2Ftornado.git Raise an error if IOLoop.start() is called while it is already running. --- diff --git a/tornado/ioloop.py b/tornado/ioloop.py index c2c520e30..d69f25cc9 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -622,6 +622,8 @@ class PollIOLoop(IOLoop): action if action is not None else signal.SIG_DFL) def start(self): + if self._running: + raise RuntimeError("IOLoop is already running") self._setup_logging() if self._stopped: self._stopped = False diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index 31afbbc49..ff26bde1e 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -234,6 +234,21 @@ class TestIOLoop(AsyncTestCase): self.io_loop.remove_handler(server_sock.fileno()) server_sock.close() + def test_reentrant(self): + """Calling start() twice should raise an error, not deadlock.""" + returned_from_start = [False] + got_exception = [False] + def callback(): + try: + self.io_loop.start() + returned_from_start[0] = True + except Exception: + got_exception[0] = True + self.stop() + self.io_loop.add_callback(callback) + self.wait() + self.assertTrue(got_exception[0]) + self.assertFalse(returned_from_start[0]) # Deliberately not a subclass of AsyncTestCase so the IOLoop isn't