]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Make fork_processes raise SystemExit instead of returning None when
authorBen Darnell <ben@bendarnell.com>
Wed, 4 Jan 2012 05:19:51 +0000 (21:19 -0800)
committerBen Darnell <ben@bendarnell.com>
Wed, 4 Jan 2012 05:19:51 +0000 (21:19 -0800)
all child processes exit cleanly.

tornado/process.py
tornado/test/process_test.py
website/sphinx/releases/next.rst

index 9e19316adc179e3f1924636c71b933bf7a68b789..06f6aa9b03a928b42d70ee2d1c035a5748dfe63a 100644 (file)
@@ -134,6 +134,11 @@ def fork_processes(num_processes, max_restarts=100):
             raise RuntimeError("Too many child restarts, giving up")
         new_id = start_child(id)
         if new_id is not None: return new_id
+    # All child processes exited cleanly, so exit the master process
+    # instead of just returning to right after the call to
+    # fork_processes (which will probably just start up another IOLoop
+    # unless the caller checks the return value).
+    sys.exit(0)
 
 def task_id():
     """Returns the current task id, if any.
index d1498fa287c0de7dae248b48db980e54088ac105..91f75b0ab62267f378faa235e83239f57b893428 100644 (file)
@@ -50,9 +50,12 @@ class ProcessTest(LogTrapTestCase):
         sockets = bind_sockets(port, "127.0.0.1")
         # ensure that none of these processes live too long
         signal.alarm(5)  # master process
-        id = fork_processes(3, max_restarts=3)
-        if id is None:
-            # back in the master process; everything worked!
+        try:
+            id = fork_processes(3, max_restarts=3)
+        except SystemExit, e:
+            # if we exit cleanly from fork_processes, all the child processes
+            # finished with status 0
+            self.assertEqual(e.code, 0)
             self.assertTrue(task_id() is None)
             for sock in sockets: sock.close()
             signal.alarm(0)
index b3bcc830c3b0a97906dc71fb79f71ae608eb0cc9..b2b9db3a21ab5bf37ff50ba4680d4f2d2b0a2244 100644 (file)
@@ -4,6 +4,14 @@ What's new in the next release of Tornado
 In progress
 -----------
 
+Backwards-incompatible changes
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+* `tornado.process.fork_processes` now raises `SystemExit` if all child
+  processes exit cleanly rather than returning ``None``.  The old behavior
+  was surprising and inconsistent with most of the documented examples
+  of this function (which did not check the return value).
+
 ``IOLoop`` and ``IOStream``
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~