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
4f61b025
Commit
4f61b025
authored
Apr 05, 2011
by
Ross Lagerwall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10963: Ensure that subprocess.communicate() never raises EPIPE.
parent
45fdb457
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
11 deletions
+55
-11
Lib/subprocess.py
Lib/subprocess.py
+34
-11
Lib/test/test_subprocess.py
Lib/test/test_subprocess.py
+19
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/subprocess.py
View file @
4f61b025
...
...
@@ -326,6 +326,7 @@ import os
import
traceback
import
gc
import
signal
import
errno
# Exception classes used by this module.
class
CalledProcessError
(
Exception
):
...
...
@@ -358,7 +359,6 @@ if mswindows:
else
:
import
select
_has_poll
=
hasattr
(
select
,
'poll'
)
import
errno
import
fcntl
import
pickle
...
...
@@ -699,7 +699,11 @@ class Popen(object):
stderr
=
None
if
self
.
stdin
:
if
input
:
try
:
self
.
stdin
.
write
(
input
)
except
IOError
as
e
:
if
e
.
errno
!=
errno
.
EPIPE
and
e
.
errno
!=
errno
.
EINVAL
:
raise
self
.
stdin
.
close
()
elif
self
.
stdout
:
stdout
=
self
.
stdout
.
read
()
...
...
@@ -929,7 +933,11 @@ class Popen(object):
if
self
.
stdin
:
if
input
is
not
None
:
try
:
self
.
stdin
.
write
(
input
)
except
IOError
as
e
:
if
e
.
errno
!=
errno
.
EPIPE
:
raise
self
.
stdin
.
close
()
if
self
.
stdout
:
...
...
@@ -1290,7 +1298,14 @@ class Popen(object):
for
fd
,
mode
in
ready
:
if
mode
&
select
.
POLLOUT
:
chunk
=
input
[
input_offset
:
input_offset
+
_PIPE_BUF
]
try
:
input_offset
+=
os
.
write
(
fd
,
chunk
)
except
OSError
as
e
:
if
e
.
errno
==
errno
.
EPIPE
:
close_unregister_and_remove
(
fd
)
else
:
raise
else
:
if
input_offset
>=
len
(
input
):
close_unregister_and_remove
(
fd
)
elif
mode
&
select_POLLIN_POLLPRI
:
...
...
@@ -1334,7 +1349,15 @@ class Popen(object):
if
self
.
stdin
in
wlist
:
chunk
=
input
[
input_offset
:
input_offset
+
_PIPE_BUF
]
try
:
bytes_written
=
os
.
write
(
self
.
stdin
.
fileno
(),
chunk
)
except
OSError
as
e
:
if
e
.
errno
==
errno
.
EPIPE
:
self
.
stdin
.
close
()
write_set
.
remove
(
self
.
stdin
)
else
:
raise
else
:
input_offset
+=
bytes_written
if
input_offset
>=
len
(
input
):
self
.
stdin
.
close
()
...
...
Lib/test/test_subprocess.py
View file @
4f61b025
...
...
@@ -592,6 +592,25 @@ class ProcessTestCase(BaseTestCase):
self
.
assertFalse
(
os
.
path
.
exists
(
ofname
))
self
.
assertFalse
(
os
.
path
.
exists
(
efname
))
def
test_communicate_epipe
(
self
):
# Issue 10963: communicate() should hide EPIPE
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'pass'
],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
self
.
addCleanup
(
p
.
stdout
.
close
)
self
.
addCleanup
(
p
.
stderr
.
close
)
self
.
addCleanup
(
p
.
stdin
.
close
)
p
.
communicate
(
b"x"
*
2
**
20
)
def
test_communicate_epipe_only_stdin
(
self
):
# Issue 10963: communicate() should hide EPIPE
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'pass'
],
stdin
=
subprocess
.
PIPE
)
self
.
addCleanup
(
p
.
stdin
.
close
)
time
.
sleep
(
2
)
p
.
communicate
(
b"x"
*
2
**
20
)
#
# POSIX tests
#
...
...
Misc/NEWS
View file @
4f61b025
...
...
@@ -44,6 +44,8 @@ Core and Builtins
Library
-------
- Issue #10963: Ensure that subprocess.communicate() never raises EPIPE.
- Issue #11696: Fix ID generation in msilib.
- Issue #9696: Fix exception incorrectly raised by xdrlib.Packer.pack_int when
...
...
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