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.
This commit is contained in:
Gregory P. Smith 2017-05-29 10:03:41 -07:00 committed by GitHub
parent eba68e2c42
commit 163468a766
8 changed files with 128 additions and 75 deletions

View file

@ -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)