From: Ben Darnell Date: Wed, 4 Jan 2012 05:19:51 +0000 (-0800) Subject: Make fork_processes raise SystemExit instead of returning None when X-Git-Tag: v2.2.0~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c23ba7e78de99c99b8e1ff1525e8017b0aa75a4;p=thirdparty%2Ftornado.git Make fork_processes raise SystemExit instead of returning None when all child processes exit cleanly. --- diff --git a/tornado/process.py b/tornado/process.py index 9e19316ad..06f6aa9b0 100644 --- a/tornado/process.py +++ b/tornado/process.py @@ -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. diff --git a/tornado/test/process_test.py b/tornado/test/process_test.py index d1498fa28..91f75b0ab 100644 --- a/tornado/test/process_test.py +++ b/tornado/test/process_test.py @@ -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) diff --git a/website/sphinx/releases/next.rst b/website/sphinx/releases/next.rst index b3bcc830c..b2b9db3a2 100644 --- a/website/sphinx/releases/next.rst +++ b/website/sphinx/releases/next.rst @@ -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`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~