Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
0768732f
Commit
0768732f
authored
Jul 06, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the wrapping of the subprocess filehandles before executing the child. Fixes Python bug 8458
parent
e5a85307
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
28 deletions
+34
-28
gevent/subprocess.py
gevent/subprocess.py
+34
-28
No files found.
gevent/subprocess.py
View file @
0768732f
...
@@ -318,6 +318,37 @@ class Popen(object):
...
@@ -318,6 +318,37 @@ class Popen(object):
c2pread
,
c2pwrite
,
c2pread
,
c2pwrite
,
errread
,
errwrite
)
=
self
.
_get_handles
(
stdin
,
stdout
,
stderr
)
errread
,
errwrite
)
=
self
.
_get_handles
(
stdin
,
stdout
,
stderr
)
# We wrap OS handles *before* launching the child, otherwise a
# quickly terminating child could make our fds unwrappable
# (see #8458).
if
mswindows
:
if
p2cwrite
is
not
None
:
p2cwrite
=
msvcrt
.
open_osfhandle
(
p2cwrite
.
Detach
(),
0
)
if
c2pread
is
not
None
:
c2pread
=
msvcrt
.
open_osfhandle
(
c2pread
.
Detach
(),
0
)
if
errread
is
not
None
:
errread
=
msvcrt
.
open_osfhandle
(
errread
.
Detach
(),
0
)
if
p2cwrite
is
not
None
:
if
PY3
and
universal_newlines
:
self
.
stdin
=
FileObject
(
p2cwrite
,
'w'
,
bufsize
)
self
.
stdin
.
_tranlate
=
True
self
.
stdin
.
io
=
io
.
TextIOWrapper
(
self
.
stdin
.
io
,
write_through
=
True
,
line_buffering
=
(
bufsize
==
1
))
else
:
self
.
stdin
=
FileObject
(
p2cwrite
,
'wb'
,
bufsize
)
if
c2pread
is
not
None
:
if
universal_newlines
:
self
.
stdout
=
FileObject
(
c2pread
,
'rU'
,
bufsize
)
else
:
self
.
stdout
=
FileObject
(
c2pread
,
'rb'
,
bufsize
)
if
errread
is
not
None
:
if
universal_newlines
:
self
.
stderr
=
FileObject
(
errread
,
'rU'
,
bufsize
)
else
:
self
.
stderr
=
FileObject
(
errread
,
'rb'
,
bufsize
)
self
.
_closed_child_pipe_fds
=
False
self
.
_closed_child_pipe_fds
=
False
try
:
try
:
self
.
_execute_child
(
args
,
executable
,
preexec_fn
,
close_fds
,
self
.
_execute_child
(
args
,
executable
,
preexec_fn
,
close_fds
,
...
@@ -328,7 +359,9 @@ class Popen(object):
...
@@ -328,7 +359,9 @@ class Popen(object):
errread
,
errwrite
)
errread
,
errwrite
)
except
:
except
:
# Cleanup if the child failed starting.
# Cleanup if the child failed starting.
# (gevent: New in python3, but reported as gevent bug in #347)
# (gevent: New in python3, but reported as gevent bug in #347.
# Note that under Py2, any error raised below will replace the
# original error. This could be worked around using hub.reraise)
for
f
in
filter
(
None
,
(
self
.
stdin
,
self
.
stdout
,
self
.
stderr
)):
for
f
in
filter
(
None
,
(
self
.
stdin
,
self
.
stdout
,
self
.
stderr
)):
try
:
try
:
f
.
close
()
f
.
close
()
...
@@ -353,33 +386,6 @@ class Popen(object):
...
@@ -353,33 +386,6 @@ class Popen(object):
raise
raise
if
mswindows
:
if
p2cwrite
is
not
None
:
p2cwrite
=
msvcrt
.
open_osfhandle
(
p2cwrite
.
Detach
(),
0
)
if
c2pread
is
not
None
:
c2pread
=
msvcrt
.
open_osfhandle
(
c2pread
.
Detach
(),
0
)
if
errread
is
not
None
:
errread
=
msvcrt
.
open_osfhandle
(
errread
.
Detach
(),
0
)
if
p2cwrite
is
not
None
:
if
PY3
and
universal_newlines
:
self
.
stdin
=
FileObject
(
p2cwrite
,
'w'
,
bufsize
)
self
.
stdin
.
_tranlate
=
True
self
.
stdin
.
io
=
io
.
TextIOWrapper
(
self
.
stdin
.
io
,
write_through
=
True
,
line_buffering
=
(
bufsize
==
1
))
else
:
self
.
stdin
=
FileObject
(
p2cwrite
,
'wb'
,
bufsize
)
if
c2pread
is
not
None
:
if
universal_newlines
:
self
.
stdout
=
FileObject
(
c2pread
,
'rU'
,
bufsize
)
else
:
self
.
stdout
=
FileObject
(
c2pread
,
'rb'
,
bufsize
)
if
errread
is
not
None
:
if
universal_newlines
:
self
.
stderr
=
FileObject
(
errread
,
'rU'
,
bufsize
)
else
:
self
.
stderr
=
FileObject
(
errread
,
'rb'
,
bufsize
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'<%s at 0x%x pid=%r returncode=%r>'
%
(
self
.
__class__
.
__name__
,
id
(
self
),
self
.
pid
,
self
.
returncode
)
return
'<%s at 0x%x pid=%r returncode=%r>'
%
(
self
.
__class__
.
__name__
,
id
(
self
),
self
.
pid
,
self
.
returncode
)
...
...
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