Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1a5426db
Commit
1a5426db
authored
Sep 21, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Merge heads
parents
52005c2e
afe8d064
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
7 deletions
+50
-7
Doc/library/subprocess.rst
Doc/library/subprocess.rst
+12
-6
Lib/subprocess.py
Lib/subprocess.py
+2
-1
Lib/test/test_subprocess.py
Lib/test/test_subprocess.py
+33
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/subprocess.rst
View file @
1a5426db
...
...
@@ -406,12 +406,18 @@ functions.
Read the `Security Considerations`_ section before using ``shell=True``.
*bufsize* will be supplied as the corresponding argument to the :func:`open`
function when creating the stdin/stdout/stderr pipe file objects: :const:`0`
means unbuffered (read and write are one system call and can return short),
:const:`1` means line buffered, any other positive value means use a buffer
of approximately that size. A negative bufsize (the default) means the
system default of io.DEFAULT_BUFFER_SIZE will be used.
*bufsize* will be supplied as the corresponding argument to the
:func:`open` function when creating the stdin/stdout/stderr pipe
file objects:
- :const:`0` means unbuffered (read and write are one
system call and can return short)
- :const:`1` means line buffered
(only usable if ``universal_newlines=True`` i.e., in a text mode)
- any other positive value means use a buffer of approximately that
size
- negative bufsize (the default) means the system default of
io.DEFAULT_BUFFER_SIZE will be used.
.. versionchanged:: 3.3.1
*bufsize* now defaults to -1 to enable buffering by default to match the
...
...
Lib/subprocess.py
View file @
1a5426db
...
...
@@ -837,7 +837,8 @@ class Popen(object):
if
p2cwrite
!=
-
1
:
self
.
stdin
=
io
.
open
(
p2cwrite
,
'wb'
,
bufsize
)
if
universal_newlines
:
self
.
stdin
=
io
.
TextIOWrapper
(
self
.
stdin
,
write_through
=
True
)
self
.
stdin
=
io
.
TextIOWrapper
(
self
.
stdin
,
write_through
=
True
,
line_buffering
=
(
bufsize
==
1
))
if
c2pread
!=
-
1
:
self
.
stdout
=
io
.
open
(
c2pread
,
'rb'
,
bufsize
)
if
universal_newlines
:
...
...
Lib/test/test_subprocess.py
View file @
1a5426db
...
...
@@ -1008,6 +1008,39 @@ class ProcessTestCase(BaseTestCase):
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"pass"
],
bufsize
=
None
)
self
.
assertEqual
(
p
.
wait
(),
0
)
def
_test_bufsize_equal_one
(
self
,
line
,
expected
,
universal_newlines
):
# subprocess may deadlock with bufsize=1, see issue #21332
with
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"import sys;"
"sys.stdout.write(sys.stdin.readline());"
"sys.stdout.flush()"
],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
DEVNULL
,
bufsize
=
1
,
universal_newlines
=
universal_newlines
)
as
p
:
p
.
stdin
.
write
(
line
)
# expect that it flushes the line in text mode
os
.
close
(
p
.
stdin
.
fileno
())
# close it without flushing the buffer
read_line
=
p
.
stdout
.
readline
()
try
:
p
.
stdin
.
close
()
except
OSError
:
pass
p
.
stdin
=
None
self
.
assertEqual
(
p
.
returncode
,
0
)
self
.
assertEqual
(
read_line
,
expected
)
def
test_bufsize_equal_one_text_mode
(
self
):
# line is flushed in text mode with bufsize=1.
# we should get the full line in return
line
=
"line
\
n
"
self
.
_test_bufsize_equal_one
(
line
,
line
,
universal_newlines
=
True
)
def
test_bufsize_equal_one_binary_mode
(
self
):
# line is not flushed in binary mode with bufsize=1.
# we should get empty response
line
=
b'line'
+
os
.
linesep
.
encode
()
# assume ascii-based locale
self
.
_test_bufsize_equal_one
(
line
,
b''
,
universal_newlines
=
False
)
def
test_leaking_fds_on_error
(
self
):
# see bug #5179: Popen leaks file descriptors to PIPEs if
# the child fails to execute; this will eventually exhaust
...
...
Misc/NEWS
View file @
1a5426db
...
...
@@ -35,6 +35,9 @@ Library
- Issue #22423: Unhandled exception in thread no longer causes unhandled
AttributeError when sys.stderr is None.
- Issue #21332: Ensure that ``bufsize=1`` in subprocess.Popen() selects
line buffering, rather than block buffering. Patch by Akira Li.
- Issue #21091: Fix API bug: email.message.EmailMessage.is_attachment is now
a method. Since EmailMessage is provisional, we can change the API in a
maintenance release, but we use a trick to remain backward compatible with
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment