]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
allow configurable max_restarts in TCPServer.start 2512/head
authorDavid Hilton <david.hilton.p@gmail.com>
Tue, 30 Oct 2018 22:37:17 +0000 (16:37 -0600)
committerDavid Hilton <david.hilton.p@gmail.com>
Wed, 31 Oct 2018 14:06:46 +0000 (08:06 -0600)
tornado/process.py
tornado/tcpserver.py

index 9e1a64500f4c8a531aa0154757345fb3311fdd73..51bb840c5b70f361faa3afb472351c3442461ecd 100644 (file)
@@ -85,7 +85,7 @@ def _pipe_cloexec() -> Tuple[int, int]:
 _task_id = None
 
 
-def fork_processes(num_processes: Optional[int], max_restarts: int = 100) -> int:
+def fork_processes(num_processes: Optional[int], max_restarts: int = None) -> int:
     """Starts multiple worker processes.
 
     If ``num_processes`` is None or <= 0, we detect the number of cores
@@ -109,7 +109,12 @@ def fork_processes(num_processes: Optional[int], max_restarts: int = 100) -> int
     process, ``fork_processes`` returns None if all child processes
     have exited normally, but will otherwise only exit by throwing an
     exception.
+
+    max_restarts defaults to 100.
     """
+    if max_restarts is None:
+        max_restarts = 100
+
     global _task_id
     assert _task_id is None
     if num_processes is None or num_processes <= 0:
index 26aec8ae9e5bda34d254b5a1d12043802f064b54..b1a561813e1c9ebc439995db9648a68c27fe279b 100644 (file)
@@ -209,7 +209,7 @@ class TCPServer(object):
         else:
             self._pending_sockets.extend(sockets)
 
-    def start(self, num_processes: Optional[int] = 1) -> None:
+    def start(self, num_processes: Optional[int] = 1, max_restarts: int = None) -> None:
         """Starts this server in the `.IOLoop`.
 
         By default, we run the server in this process and do not fork any
@@ -232,7 +232,7 @@ class TCPServer(object):
         assert not self._started
         self._started = True
         if num_processes != 1:
-            process.fork_processes(num_processes)
+            process.fork_processes(num_processes, max_restarts)
         sockets = self._pending_sockets
         self._pending_sockets = []
         self.add_sockets(sockets)