Преглед на файлове

make_process is now a responsibility of the process group config.

Chris McDonough преди 18 години
родител
ревизия
e768bb8518
променени са 5 файла, в които са добавени 26 реда и са изтрити 13 реда
  1. 6 6
      src/supervisor/options.py
  2. 9 3
      src/supervisor/process.py
  3. 4 3
      src/supervisor/tests/base.py
  4. 7 0
      src/supervisor/tests/test_options.py
  5. 0 1
      src/supervisor/tests/test_rpcinterfaces.py

+ 6 - 6
src/supervisor/options.py

@@ -1182,10 +1182,6 @@ class ServerOptions(Options):
         for msg in info_messages:
             self.logger.info(msg)
 
-    def make_process(self, config):
-        from supervisor.process import Subprocess
-        return Subprocess(config)
-
     def make_pipes(self, stderr=True):
         """ Create pipes for parent to child stdin/stdout/stderr
         communications.  Open fd in nonblocking mode so we can read them
@@ -1504,6 +1500,10 @@ class ProcessConfig(Config):
                 logfile_maxbytes = self.stdout_logfile_maxbytes,
                 capturefile = self.stdout_capturefile)
 
+    def make_process(self):
+        from supervisor.process import Subprocess
+        return Subprocess(self)
+
 class ProcessGroupConfig(Config):
     def __init__(self, options, name, priority, process_configs):
         self.options = options
@@ -1532,8 +1532,8 @@ class EventListenerPoolConfig(Config):
             config.create_autochildlogs()
 
     def make_group(self):
-        from supervisor.process import ProcessGroup
-        return ProcessGroup(self)
+        from supervisor.process import EventListenerPool
+        return EventListenerPool(self)
 
 class BasicAuthTransport(xmlrpclib.Transport):
     """ A transport that understands basic auth and UNIX domain socket

+ 9 - 3
src/supervisor/process.py

@@ -416,13 +416,13 @@ class Subprocess:
             return ProcessStates.RUNNING
         return ProcessStates.UNKNOWN
 
-class ProcessGroup:
+
+class ProcessGroupBase:
     def __init__(self, config):
         self.config = config
         self.processes = {}
         for pconfig in self.config.process_configs:
-            options = self.config.options
-            self.processes[pconfig.name] = options.make_process(pconfig)
+            self.processes[pconfig.name] = pconfig.make_process()
         
 
     def __cmp__(self, other):
@@ -550,6 +550,12 @@ class ProcessGroup:
             dispatchers.update(process.dispatchers)
         return dispatchers
 
+class ProcessGroup(ProcessGroupBase):
+    pass
+
+class EventListenerPool(ProcessGroupBase):
+    pass
+
 class PDispatcher:
     """ Asyncore dispatcher for mainloop, representing a process channel
     (stdin, stdout, or stderr).  This class is abstract. """

+ 4 - 3
src/supervisor/tests/base.py

@@ -111,9 +111,6 @@ class DummyOptions:
     def waitpid(self):
         return self.waitpid_return
 
-    def make_process(self, config):
-        return DummyProcess(config)
-
     def kill(self, pid, sig):
         if self.kill_error:
             raise OSError(self.kill_error)
@@ -426,6 +423,10 @@ class DummyPConfig:
     def make_stderr_recorder(self):
         return DummyRecorder()
 
+    def make_process(self):
+        return DummyProcess(self)
+
+
 def makeExecutable(file, substitutions=None):
     import os
     import sys

+ 7 - 0
src/supervisor/tests/test_options.py

@@ -715,6 +715,13 @@ class TestProcessConfig(unittest.TestCase):
         from supervisor.recorders import LoggingRecorder
         self.assertEqual(recorder.capturelog, None)
 
+    def test_make_process(self):
+        options = DummyOptions()
+        instance = self._makeOne(options)
+        process = instance.make_process()
+        from supervisor.process import Subprocess
+        self.assertEqual(process.__class__, Subprocess)
+
 class ProcessGroupConfigTests(unittest.TestCase):
     def _getTargetClass(self):
         from supervisor.options import ProcessGroupConfig

+ 0 - 1
src/supervisor/tests/test_rpcinterfaces.py

@@ -868,7 +868,6 @@ class SupervisorNamespaceXMLRPCInterfaceTests(TestBase):
         interface = self._makeOne(supervisord)
         self.assertRaises(xmlrpc.RPCError, interface.clearProcessLog, 'foo')
         
-
     def test_clearAllProcessLogs(self):
         options = DummyOptions()
         pconfig1 = DummyPConfig(options, 'process1', 'foo')