فهرست منبع

Fix signal() error handler
AttributeError: class StringIO has no attribute 'StringIO'

Mike Naberezny 10 سال پیش
والد
کامیت
4f3abd61d9
2فایلهای تغییر یافته به همراه23 افزوده شده و 3 حذف شده
  1. 1 3
      supervisor/process.py
  2. 22 0
      supervisor/tests/test_process.py

+ 1 - 3
supervisor/process.py

@@ -464,9 +464,7 @@ class Subprocess:
         try:
             options.kill(self.pid, sig)
         except:
-            io = StringIO.StringIO()
-            traceback.print_exc(file=io)
-            tb = io.getvalue()
+            tb = traceback.format_exc()
             msg = 'unknown problem sending sig %s (%s):%s' % (
                                 self.config.name, self.pid, tb)
             options.logger.critical(msg)

+ 22 - 0
supervisor/tests/test_process.py

@@ -952,6 +952,28 @@ class SubprocessTests(unittest.TestCase):
 
         self.assertEqual(killedpid, [])
 
+    def test_signal_error(self):
+        options = DummyOptions()
+        config = DummyPConfig(options, 'test', '/test')
+        options.kill_error = 1
+        instance = self._makeOne(config)
+        L = []
+        from supervisor.states import ProcessStates
+        from supervisor import events
+        events.subscribe(events.ProcessStateEvent,
+                         lambda x: L.append(x))
+        instance.pid = 11
+        instance.state = ProcessStates.RUNNING
+        instance.signal(signal.SIGWINCH)
+        self.assertEqual(options.logger.data[0],
+            'sending test (pid 11) sig SIGWINCH')
+        self.assertTrue(options.logger.data[1].startswith(
+            'unknown problem sending sig test (11)'))
+        self.assertEqual(instance.killing, 0)
+        self.assertEqual(len(L), 1)
+        event = L[0]
+        self.assertEqual(event.__class__, events.ProcessStateUnknownEvent)
+
     def test_finish_stopping_state(self):
         options = DummyOptions()
         config = DummyPConfig(options, 'notthere', '/notthere',