diff options
author | Victor Stinner <vstinner@python.org> | 2020-04-24 10:06:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-24 10:06:58 (GMT) |
commit | e6f8abd500751a834b6fff4f107ecbd29f2184fe (patch) | |
tree | b6c864b0239aba840849bb4dba8a94d7b57b5b68 /Modules | |
parent | 162c567d164b5742c0d1f3f8bd8c8bab9c117cd0 (diff) | |
download | cpython-e6f8abd500751a834b6fff4f107ecbd29f2184fe.zip cpython-e6f8abd500751a834b6fff4f107ecbd29f2184fe.tar.gz cpython-e6f8abd500751a834b6fff4f107ecbd29f2184fe.tar.bz2 |
bpo-38061: subprocess uses closefrom() on FreeBSD (GH-19697)
Optimize the subprocess module on FreeBSD using closefrom().
A single close(fd) syscall is cheap, but when sysconf(_SC_OPEN_MAX)
is high, the loop calling close(fd) on each file descriptor can take
several milliseconds.
The workaround on FreeBSD to improve performance was to load and
mount the fdescfs kernel module, but this is not enabled by default.
Initial patch by Ed Maste (emaste), Conrad Meyer (cem), Kyle Evans
(kevans) and Kubilay Kocak (koobs):
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=242274
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_posixsubprocess.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index 7d5a7fe..60dd78d 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -264,9 +264,15 @@ _close_fds_by_brute_force(long start_fd, PyObject *py_fds_to_keep) start_fd = keep_fd + 1; } if (start_fd <= end_fd) { +#if defined(__FreeBSD__) + /* Any errors encountered while closing file descriptors are ignored */ + closefrom(start_fd); +#else for (fd_num = start_fd; fd_num < end_fd; ++fd_num) { - close(fd_num); + /* Ignore errors */ + (void)close(fd_num); } +#endif } } |