[New-bugs-announce] [issue38061] FreeBSD: Optimize subprocess.Popen(close_fds=True) using closefrom()

STINNER Victor report at bugs.python.org
Mon Sep 9 03:25:36 EDT 2019

New submission from STINNER Victor <vstinner at python.org>:

The default value of subprocess.Popen "close_fds" parameter changed to True in Python 3. Compared to Python 2, close_fds=True can make Popen 10x slower: see bpo-37790.

A single close(fd) syscall is cheap. But when MAXFDS (maximum file descriptor number) is high, the loop calling close(fd) on each file descriptor can take several milliseconds.

On FreeBSD, the _posixsubprocess could use closefrom() to reduce the number of syscalls.

On Linux, _posixsubprocess lists the content of /proc/self/fd/ to only close open file descriptor, after fork() and before exec().

components: Library (Lib)
messages: 351351
nosy: vstinner
priority: normal
severity: normal
status: open
title: FreeBSD: Optimize subprocess.Popen(close_fds=True) using closefrom()
type: enhancement
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list