1. Brent Tubbs
  2. CherryPy


Robert Brewer  committed 5640ee0

server.stop() works now even if init_only is False.

  • Participants
  • Parent commits cd44e5d
  • Branches default

Comments (0)

Files changed (3)

File cherrypy/_cpengine.py

View file
  • Ignore whitespace
         self.state = STARTED
     def block(self):
-        """Block forever (wait for KeyboardInterrupt or SystemExit)."""
+        """Block forever (wait for stop(), KeyboardInterrupt or SystemExit)."""
-            while True:
+            while self.state != STOPPED:
                 if self.interrupt:
                     raise self.interrupt

File cherrypy/_cpserver.py

View file
  • Ignore whitespace
     def wait_for_http_ready(self):
         if self.httpserver:
-            while not getattr(self.httpserver, "ready", True) and not self.interrupt:
+            while (not getattr(self.httpserver, "ready", True)
+                   and not self.interrupt
+                   and self.state != STOPPED):
             # Wait for port to be occupied

File cherrypy/test/test_states.py

View file
  • Ignore whitespace
             # error again. (If we were running an HTTP server,
             # then the connection should not even be processed).
             self.assertRaises(cherrypy.NotReady, self.getPage, "/")
+        # Block the main thread now and verify that stop() works.
+        def stoptest():
+            self.getPage("/")
+            self.assertBody("Hello World")
+            cherrypy.server.stop()
+        cherrypy.server.start_with_callback(stoptest, server_class=self.server_class)
+        self.assertEqual(cherrypy.server.state, 0)
     def test_1_Restart(self):
         cherrypy.server.start(True, self.server_class)