فهرست منبع

Cause things which are written to a suprocess' "writebuffer" to be flushed to the child's stdin.

Chris McDonough 18 سال پیش
والد
کامیت
7d6685593c
3فایلهای تغییر یافته به همراه20 افزوده شده و 6 حذف شده
  1. 1 1
      src/supervisor/process.py
  2. 18 4
      src/supervisor/supervisord.py
  3. 1 1
      src/supervisor/tests.py

+ 1 - 1
src/supervisor/process.py

@@ -190,8 +190,8 @@ class Subprocess:
                 sent = self.options.write(self.pipes['stdin'], to_send)
                 self.writebuffer = self.writebuffer[sent:]
             except OSError, why:
-                msg = 'failed writing to process %r stdin' % self.config.name
                 if why[0] == errno.EPIPE:
+                    msg = 'failed write to process %r stdin' % self.config.name
                     self.writebuffer = ''
                     self.options.logger.info(msg)
                 else:

+ 18 - 4
src/supervisor/supervisord.py

@@ -146,14 +146,23 @@ class Supervisor:
 
             process_map = {}
 
-            # process output fds
+            # process input and output
             for proc in self.processes.values():
                 proc.log_output()
-                drains = proc.get_output_drains()
-                for fd, drain in drains:
+
+                # process output fds
+                output_drains = proc.get_output_drains()
+                for fd, drain in output_drains:
                     r.append(fd)
                     process_map[fd] = drain
 
+                # process input fds
+                if proc.writebuffer:
+                    input_drains = proc.get_input_drains()
+                    for fd, drain in input_drains:
+                        w.append(fd)
+                        process_map[fd] = drain
+
             # medusa i/o fds
             for fd, dispatcher in socket_map.items():
                 if dispatcher.readable():
@@ -175,7 +184,7 @@ class Supervisor:
             for fd in r:
                 if process_map.has_key(fd):
                     drain = process_map[fd]
-                    # drain the file descriptor
+                    # drain the file descriptor data to the logbuffer
                     drain()
 
                 if socket_map.has_key(fd):
@@ -187,6 +196,11 @@ class Supervisor:
                         socket_map[fd].handle_error()
 
             for fd in w:
+                if process_map.has_key(fd):
+                    # drain the writebuffer by sending it to child's stdin
+                    drain = process_map[fd]
+                    drain()
+
                 if socket_map.has_key(fd):
                     try:
                         socket_map[fd].handle_write_event()

+ 1 - 1
src/supervisor/tests.py

@@ -1410,7 +1410,7 @@ class SubprocessTests(unittest.TestCase):
         instance.drain_stdin()
         self.assertEqual(instance.writebuffer, '')
         self.assertEqual(options.logger.data,
-            ["failed writing to process 'test' stdin"])
+            ["failed write to process 'test' stdin"])
 
     def test_drain_stdin_uncaught_oserror(self):
         options = DummyOptions()