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
23109f00
Commit
23109f00
authored
Mar 03, 2005
by
Peter Astrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimization for communicate(): If only one of stdin/stdout/stderr is
redirected, using select() or threads is unnecessary.
parent
cbac93c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
16 deletions
+29
-16
Lib/subprocess.py
Lib/subprocess.py
+29
-16
No files found.
Lib/subprocess.py
View file @
23109f00
...
...
@@ -619,6 +619,33 @@ class Popen(object):
data
=
data
.
replace
(
"
\
r
"
,
"
\
n
"
)
return
data
def
communicate
(
self
,
input
=
None
):
"""Interact with process: Send data to stdin. Read data from
stdout and stderr, until end-of-file is reached. Wait for
process to terminate. The optional input argument should be a
string to be sent to the child process, or None, if no data
should be sent to the child.
communicate() returns a tuple (stdout, stderr)."""
# Optimization: If we are only using one pipe, or no pipe at
# all, using select() or threads is unnecessary.
if
[
self
.
stdin
,
self
.
stdout
,
self
.
stderr
].
count
(
None
)
>=
2
:
stdout
=
None
stderr
=
None
if
self
.
stdin
:
if
input
:
self
.
stdin
.
write
(
input
)
self
.
stdin
.
close
()
elif
self
.
stdout
:
stdout
=
self
.
stdout
.
read
()
elif
self
.
stderr
:
stderr
=
self
.
stderr
.
read
()
self
.
wait
()
return
(
stdout
,
stderr
)
return
self
.
_communicate
(
input
)
if
mswindows
:
#
...
...
@@ -811,14 +838,7 @@ class Popen(object):
buffer
.
append
(
fh
.
read
())
def
communicate
(
self
,
input
=
None
):
"""Interact with process: Send data to stdin. Read data from
stdout and stderr, until end-of-file is reached. Wait for
process to terminate. The optional input argument should be a
string to be sent to the child process, or None, if no data
should be sent to the child.
communicate() returns a tuple (stdout, stderr)."""
def
_communicate
(
self
,
input
):
stdout
=
None
# Return
stderr
=
None
# Return
...
...
@@ -1066,14 +1086,7 @@ class Popen(object):
return
self
.
returncode
def
communicate
(
self
,
input
=
None
):
"""Interact with process: Send data to stdin. Read data from
stdout and stderr, until end-of-file is reached. Wait for
process to terminate. The optional input argument should be a
string to be sent to the child process, or None, if no data
should be sent to the child.
communicate() returns a tuple (stdout, stderr)."""
def
_communicate
(
self
,
input
):
read_set
=
[]
write_set
=
[]
stdout
=
None
# Return
...
...
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