[Python-checkins] cpython (3.5): Issue #26848: Fix asyncio/subprocess.communicate() to handle empty input.
yury.selivanov
python-checkins at python.org
Fri May 13 15:39:14 EDT 2016
https://hg.python.org/cpython/rev/148757a88f19
changeset: 101321:148757a88f19
branch: 3.5
parent: 101318:ae50bf6e3ac8
user: Yury Selivanov <yselivanov at sprymix.com>
date: Fri May 13 15:35:28 2016 -0400
summary:
Issue #26848: Fix asyncio/subprocess.communicate() to handle empty input.
files:
Lib/asyncio/subprocess.py | 2 +-
Lib/test/test_asyncio/test_subprocess.py | 19 ++++++++++++
Misc/NEWS | 3 +
3 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/Lib/asyncio/subprocess.py b/Lib/asyncio/subprocess.py
--- a/Lib/asyncio/subprocess.py
+++ b/Lib/asyncio/subprocess.py
@@ -166,7 +166,7 @@
@coroutine
def communicate(self, input=None):
- if input:
+ if input is not None:
stdin = self._feed_stdin(input)
else:
stdin = self._noop()
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -287,6 +287,25 @@
self.assertEqual(output.rstrip(), b'3')
self.assertEqual(exitcode, 0)
+ def test_empty_input(self):
+ @asyncio.coroutine
+ def empty_input():
+ code = 'import sys; data = sys.stdin.read(); print(len(data))'
+ proc = yield from asyncio.create_subprocess_exec(
+ sys.executable, '-c', code,
+ stdin=asyncio.subprocess.PIPE,
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE,
+ close_fds=False,
+ loop=self.loop)
+ stdout, stderr = yield from proc.communicate(b'')
+ exitcode = yield from proc.wait()
+ return (stdout, exitcode)
+
+ output, exitcode = self.loop.run_until_complete(empty_input())
+ self.assertEqual(output.rstrip(), b'0')
+ self.assertEqual(exitcode, 0)
+
def test_cancel_process_wait(self):
# Issue #23140: cancel Process.wait()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -436,6 +436,9 @@
- Issue #26406: Avoid unnecessary serialization of getaddrinfo(3) calls on
current versions of OpenBSD and NetBSD. Patch by A. Jesse Jiryu Davis.
+- Issue #26848: Fix asyncio/subprocess.communicate() to handle empty input.
+ Patch by Jack O'Connor.
+
Documentation
-------------
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list