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
6a77c2d9
Commit
6a77c2d9
authored
Dec 05, 2015
by
Martin Panter
Browse files
Options
Browse Files
Download
Plain Diff
Issue #25764: Merge subprocess fix from 3.4 into 3.5
parents
ccddbb18
afdd5134
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
17 deletions
+37
-17
Lib/test/test_subprocess.py
Lib/test/test_subprocess.py
+16
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_posixsubprocess.c
Modules/_posixsubprocess.c
+18
-17
No files found.
Lib/test/test_subprocess.py
View file @
6a77c2d9
...
...
@@ -1512,6 +1512,22 @@ class POSIXProcessTestCase(BaseTestCase):
if
not
enabled
:
gc
.
disable
()
def
test_preexec_fork_failure
(
self
):
# The internal code did not preserve the previous exception when
# re-enabling garbage collection
try
:
from
resource
import
getrlimit
,
setrlimit
,
RLIMIT_NPROC
except
ImportError
as
err
:
self
.
skipTest
(
err
)
# RLIMIT_NPROC is specific to Linux and BSD
limits
=
getrlimit
(
RLIMIT_NPROC
)
[
_
,
hard
]
=
limits
setrlimit
(
RLIMIT_NPROC
,
(
0
,
hard
))
self
.
addCleanup
(
setrlimit
,
RLIMIT_NPROC
,
limits
)
# Forking should raise EAGAIN, translated to BlockingIOError
with
self
.
assertRaises
(
BlockingIOError
):
subprocess
.
call
([
sys
.
executable
,
'-c'
,
''
],
preexec_fn
=
lambda
:
None
)
def
test_args_string
(
self
):
# args is a string
fd
,
fname
=
tempfile
.
mkstemp
()
...
...
Misc/NEWS
View file @
6a77c2d9
...
...
@@ -22,6 +22,9 @@ Core and Builtins
Library
-------
- Issue #25764: In the subprocess module, preserve any exception caused by
fork() failure when preexec_fn is used.
- Issue #6478: _strptime'
s
regexp
cache
now
is
reset
after
changing
timezone
with
time
.
tzset
().
...
...
Modules/_posixsubprocess.c
View file @
6a77c2d9
...
...
@@ -47,17 +47,25 @@
#define POSIX_CALL(call) do { if ((call) == -1) goto error; } while (0)
/*
Given the gc module call gc.enable() and r
eturn 0 on success. */
/*
If gc was disabled, call gc.enable(). R
eturn 0 on success. */
static
int
_enable_gc
(
PyObject
*
gc_module
)
_enable_gc
(
int
need_to_reenable_gc
,
PyObject
*
gc_module
)
{
PyObject
*
result
;
_Py_IDENTIFIER
(
enable
);
PyObject
*
exctype
,
*
val
,
*
tb
;
result
=
_PyObject_CallMethodId
(
gc_module
,
&
PyId_enable
,
NULL
);
if
(
result
==
NULL
)
return
1
;
Py_DECREF
(
result
);
if
(
need_to_reenable_gc
)
{
PyErr_Fetch
(
&
exctype
,
&
val
,
&
tb
);
result
=
_PyObject_CallMethodId
(
gc_module
,
&
PyId_enable
,
NULL
);
if
(
exctype
!=
NULL
)
{
PyErr_Restore
(
exctype
,
val
,
tb
);
}
if
(
result
==
NULL
)
{
return
1
;
}
Py_DECREF
(
result
);
}
return
0
;
}
...
...
@@ -698,6 +706,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
&&
_PyImport_ReleaseLock
()
<
0
&&
!
PyErr_Occurred
())
{
PyErr_SetString
(
PyExc_RuntimeError
,
"not holding the import lock"
);
pid
=
-
1
;
}
import_lock_held
=
0
;
#endif
...
...
@@ -710,9 +719,8 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
_Py_FreeCharPArray
(
exec_array
);
/* Reenable gc in the parent process (or if fork failed). */
if
(
need_to_reenable_gc
&&
_enable_gc
(
gc_module
))
{
Py_XDECREF
(
gc_module
);
return
NULL
;
if
(
_enable_gc
(
need_to_reenable_gc
,
gc_module
))
{
pid
=
-
1
;
}
Py_XDECREF
(
preexec_fn_args_tuple
);
Py_XDECREF
(
gc_module
);
...
...
@@ -736,14 +744,7 @@ cleanup:
Py_XDECREF
(
converted_args
);
Py_XDECREF
(
fast_args
);
Py_XDECREF
(
preexec_fn_args_tuple
);
/* Reenable gc if it was disabled. */
if
(
need_to_reenable_gc
)
{
PyObject
*
exctype
,
*
val
,
*
tb
;
PyErr_Fetch
(
&
exctype
,
&
val
,
&
tb
);
_enable_gc
(
gc_module
);
PyErr_Restore
(
exctype
,
val
,
tb
);
}
_enable_gc
(
need_to_reenable_gc
,
gc_module
);
Py_XDECREF
(
gc_module
);
return
NULL
;
}
...
...
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