summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-11-25 17:21:43 +0100
committerVictor Stinner <victor.stinner@gmail.com>2014-11-25 17:21:43 +0100
commit6a11e5e1aed1cb3566edb41d9f4a6b490abb2581 (patch)
treee9fca62df358be222bc35970b2e43bb0bad2d639 /Lib/test
parent166ebc4e5dd09f005c6144b7568da83728b8b893 (diff)
parent5ef586f25a6d5128a15341e849d7dca4fe882d22 (diff)
downloadcpython-git-6a11e5e1aed1cb3566edb41d9f4a6b490abb2581.tar.gz
(Merge 3.4) Closes #22685, asyncio: Set the transport of stdout and stderr
StreamReader objects in the SubprocessStreamProtocol. It allows to pause the transport to not buffer too much stdout or stderr data.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index 0e9e1ce5f9..d0ab23080d 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -4,6 +4,7 @@ import asyncio
import signal
import sys
import unittest
+from unittest import mock
from test import support
if sys.platform != 'win32':
from asyncio import unix_events
@@ -161,6 +162,37 @@ class SubprocessMixin:
self.loop.run_until_complete(proc.communicate(large_data))
self.loop.run_until_complete(proc.wait())
+ def test_pause_reading(self):
+ @asyncio.coroutine
+ def test_pause_reading():
+ limit = 100
+
+ code = '\n'.join((
+ 'import sys',
+ 'sys.stdout.write("x" * %s)' % (limit * 2 + 1),
+ 'sys.stdout.flush()',
+ ))
+ proc = yield from asyncio.create_subprocess_exec(
+ sys.executable, '-c', code,
+ stdin=asyncio.subprocess.PIPE,
+ stdout=asyncio.subprocess.PIPE,
+ limit=limit,
+ loop=self.loop)
+ stdout_transport = proc._transport.get_pipe_transport(1)
+ stdout_transport.pause_reading = mock.Mock()
+
+ yield from proc.wait()
+
+ # The child process produced more than limit bytes of output,
+ # the stream reader transport should pause the protocol to not
+ # allocate too much memory.
+ return stdout_transport.pause_reading.called
+
+ # Issue #22685: Ensure that the stream reader pauses the protocol
+ # when the child process produces too much data
+ called = self.loop.run_until_complete(test_pause_reading())
+ self.assertTrue(called)
+
if sys.platform != 'win32':
# Unix