]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Raise an error if IOLoop.start() is called while it is already running.
authorBen Darnell <ben@bendarnell.com>
Sat, 25 Jan 2014 22:16:17 +0000 (17:16 -0500)
committerBen Darnell <ben@bendarnell.com>
Sat, 25 Jan 2014 22:16:17 +0000 (17:16 -0500)
tornado/ioloop.py
tornado/test/ioloop_test.py

index c2c520e3022ad8423b8f70641bf82cd53d473108..d69f25cc903fc63ce59ffbdef0b3fc1b06c55945 100644 (file)
@@ -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
index 31afbbc498b17cd48bad386d3b61b262ebfe1c67..ff26bde1e11699232166078c64c703d83418664b 100644 (file)
@@ -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