os.dup2() tests for dup3() system call availability at runtime,
but doesn't remember the result across calls, repeating
the test on each call with inheritable=False.
Since the caller of os.dup2() is expected to hold the GIL,
fix this by making the variable holding the test result static.
--- /dev/null
+In ``os.dup2``, don't check every call whether the ``dup3`` syscall exists
+or not.
#if defined(HAVE_DUP3) && \
!(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
/* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
- int dup3_works = -1;
+ static int dup3_works = -1;
#endif
if (fd < 0 || fd2 < 0) {