diff options
author | Gregory P. Smith <greg@krypto.org> | 2017-05-29 10:03:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-29 10:03:41 -0700 |
commit | 163468a766e16604bdea04a1ab808c0d3e729e5d (patch) | |
tree | d9c9bb6da480f4d7e9070e83a010798da5c30a6f /Modules/_posixsubprocess.c | |
parent | eba68e2c42e149acecb15bbeb692786e2540157d (diff) | |
download | cpython-git-163468a766e16604bdea04a1ab808c0d3e729e5d.tar.gz |
bpo-16500: Don't use string constants for os.register_at_fork() behavior (#1834)
Instead use keyword only arguments to os.register_at_fork for each of the scenarios.
Updates the documentation for clarity.
Diffstat (limited to 'Modules/_posixsubprocess.c')
-rw-r--r-- | Modules/_posixsubprocess.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index 5228fecfa9..8c8777cfe3 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -651,14 +651,6 @@ subprocess_fork_exec(PyObject* self, PyObject *args) goto cleanup; } - if (preexec_fn != Py_None) { - preexec_fn_args_tuple = PyTuple_New(0); - if (!preexec_fn_args_tuple) - goto cleanup; - PyOS_BeforeFork(); - need_after_fork = 1; - } - if (cwd_obj != Py_None) { if (PyUnicode_FSConverter(cwd_obj, &cwd_obj2) == 0) goto cleanup; @@ -668,6 +660,17 @@ subprocess_fork_exec(PyObject* self, PyObject *args) cwd_obj2 = NULL; } + /* This must be the last thing done before fork() because we do not + * want to call PyOS_BeforeFork() if there is any chance of another + * error leading to the cleanup: code without calling fork(). */ + if (preexec_fn != Py_None) { + preexec_fn_args_tuple = PyTuple_New(0); + if (!preexec_fn_args_tuple) + goto cleanup; + PyOS_BeforeFork(); + need_after_fork = 1; + } + pid = fork(); if (pid == 0) { /* Child process */ @@ -722,8 +725,6 @@ subprocess_fork_exec(PyObject* self, PyObject *args) return PyLong_FromPid(pid); cleanup: - if (need_after_fork) - PyOS_AfterFork_Parent(); if (envp) _Py_FreeCharPArray(envp); if (argv) |