python / cpython

The Python programming language
https://www.python.org
Other
63.49k stars 30.41k forks source link

Popen should use pidfd_open to implement a non-busy wait #83069

Open b7b6ade5-7451-4d6f-b8d7-b2161f50e41f opened 4 years ago

b7b6ade5-7451-4d6f-b8d7-b2161f50e41f commented 4 years ago
BPO 38888
Nosy @gpshead, @vstinner, @benjaminp, @SpecLad

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['type-feature', 'library', '3.9'] title = 'Popen should use pidfd_open to implement a non-busy wait' updated_at = user = 'https://github.com/SpecLad' ``` bugs.python.org fields: ```python activity = actor = 'SpecLad' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'SpecLad' dependencies = [] files = [] hgrepos = [] issue_num = 38888 keywords = [] message_count = 3.0 messages = ['357222', '357223', '357225'] nosy_count = 4.0 nosy_names = ['gregory.p.smith', 'vstinner', 'benjamin.peterson', 'SpecLad'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue38888' versions = ['Python 3.9'] ```

b7b6ade5-7451-4d6f-b8d7-b2161f50e41f commented 4 years ago

Popen.wait(timeout) is currently implemented on Unix-like systems using a busy wait, since the waitpid system call doesn't have a timeout argument.

On Linux, it's now possible to do better than that. You can create a PID file descriptor using pidfd_create and poll that descriptor with the specified timeout. Popen.wait should make use of that.

vstinner commented 4 years ago

os.pidfd_open() was added to Python 3.9. Do you mean pidfd_open()?

b7b6ade5-7451-4d6f-b8d7-b2161f50e41f commented 4 years ago

Right, of course. I keep confusing it with timerfd_create.