Pārlūkot izejas kodu

Merge pull request #118 from pvaret/master

Allow users to stop a process in BACKOFF state.
Mike Naberezny 11 gadi atpakaļ
vecāks
revīzija
f908ff78bb
2 mainītis faili ar 26 papildinājumiem un 1 dzēšanām
  1. 10 1
      supervisor/process.py
  2. 16 0
      supervisor/tests/test_process.py

+ 10 - 1
supervisor/process.py

@@ -366,6 +366,15 @@ class Subprocess:
         """
         now = time.time()
         options = self.config.options
+
+        # Properly stop processes in BACKOFF state.
+        if self.state == ProcessStates.BACKOFF:
+            msg = ("Attempted to kill %s, which is in BACKOFF state." %
+                   (self.config.name))
+            options.logger.debug(msg)
+            self.change_state(ProcessStates.STOPPED)
+            return None
+
         if not self.pid:
             msg = ("attempted to kill %s with sig %s but it wasn't running" %
                    (self.config.name, signame(sig)))
@@ -760,7 +769,7 @@ class EventListenerPool(ProcessGroupBase):
     def _acceptEvent(self, event, head=False):
         # events are required to be instances
         # this has a side effect to fail with an attribute error on 'old style' classes
-        event_type = event.__class__ 
+        event_type = event.__class__
         if not hasattr(event, 'serial'):
             event.serial = new_serial(GlobalSerial)
         if not hasattr(event, 'pool_serials'):

+ 16 - 0
supervisor/tests/test_process.py

@@ -754,6 +754,22 @@ class SubprocessTests(unittest.TestCase):
         self.assertEqual(options.kills[11], signal.SIGKILL)
         self.assertEqual(L, []) # no event because we didn't change state
 
+    def test_kill_from_backoff(self):
+        options = DummyOptions()
+        config = DummyPConfig(options, 'test', '/test')
+        instance = self._makeOne(config)
+        L = []
+        from supervisor.states import ProcessStates
+        from supervisor import events
+        events.subscribe(events.Event, L.append)
+        instance.state = ProcessStates.BACKOFF
+        instance.kill(signal.SIGKILL)
+        self.assertEqual(options.logger.data[0],
+                         'Attempted to kill test, which is in BACKOFF state.')
+        self.assertEqual(instance.killing, 0)
+        event = L[0]
+        self.assertEqual(event.__class__, events.ProcessStateStoppedEvent)
+
     def test_kill_from_stopping_w_killasgroup(self):
         options = DummyOptions()
         config = DummyPConfig(options, 'test', '/test', killasgroup=True)