diff --git a/AUTHORS b/AUTHORS index 264b35e..f0c1b5a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -23,10 +23,11 @@ Linden Lab Contributors Thanks To --------- +* Chuck Thier, reporting a bug in processes.py * Brantley Harris, reporting bug #4 * Taso Du Val, reproing an exception squelching bug, saving children's lives ;-) * R. Tyler Ballance, bug report on tpool on Windows, help with improving corolocal module -* Sergey Shepelev, PEP 8 police :-) +* Sergey Shepelev, PEP 8 police :-), reporting bug #5 * Luci Stanescu, for reporting twisted hub bug * Marcus Cavanaugh, for test case code that has been incredibly useful in tracking down bugs * Brian Brunswick, for many helpful questions and suggestions on the mailing list diff --git a/NEWS b/NEWS index a87d8be..d74e86d 100644 --- a/NEWS +++ b/NEWS @@ -13,8 +13,7 @@ * Added support for logging x-forwarded-for header in wsgi. * api.tcp_server is now deprecated, will be removed in a future release. * Added instructions on how to generate coverage reports to the documentation. -* Bug fixes in: wsgi.py, twistedr.py, poll.py, greenio.py, util.py, select.py - +* Bug fixes in: wsgi.py, twistedr.py, poll.py, greenio.py, util.py, select.py, processes.py 0.9.0 ===== diff --git a/eventlet/processes.py b/eventlet/processes.py index 095f0ae..d13bd18 100644 --- a/eventlet/processes.py +++ b/eventlet/processes.py @@ -76,6 +76,7 @@ class Process(object): self.send = self.child_stdin.write self.recv = self.child_stdout_stderr.read self.readline = self.child_stdout_stderr.readline + self._read_first_result = False def wait(self): return cooperative_wait(self.popen4) @@ -94,11 +95,17 @@ class Process(object): raise RuntimeError("Unknown mode", mode) def read(self, amount=None): + """Reads from the stdout and stderr of the child process. + The first call to read() will return a string; subsequent + calls may raise a DeadProcess when EOF occurs on the pipe. + """ result = self.child_stdout_stderr.read(amount) - if result == '': + if result == '' and self._read_first_result: # This process is dead. self.dead_callback() raise DeadProcess + else: + self._read_first_result = True return result def write(self, stuff): diff --git a/tests/processes_test.py b/tests/processes_test.py index ed131f1..2bcd81e 100644 --- a/tests/processes_test.py +++ b/tests/processes_test.py @@ -24,7 +24,12 @@ class TestEchoPool(TestCase): self.assertRaises(processes.DeadProcess, proc.read) finally: self.pool.put(proc) - + + def test_empty_echo(self): + p = processes.Process('echo', ['-n']) + self.assertEquals('', p.read()) + self.assertRaises(processes.DeadProcess, p.read) + class TestCatPool(TestCase): def setUp(self):