Skip to content

Commit 1ddc52b

Browse files
committed
Replace _can_use_kqueue() -> _CAN_USE_KQUEUE
1 parent e807ba9 commit 1ddc52b

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

Lib/subprocess.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -749,18 +749,16 @@ def _use_posix_spawn():
749749
# By default, assume that posix_spawn() does not properly report errors.
750750
return False
751751

752-
753-
@functools.lru_cache
754-
def _can_use_kqueue():
755-
names = (
752+
_CAN_USE_KQUEUE = all(
753+
hasattr(select, x)
754+
for x in (
756755
"kqueue",
757756
"KQ_EV_ADD",
758757
"KQ_EV_ONESHOT",
759758
"KQ_FILTER_PROC",
760759
"KQ_NOTE_EXIT",
761760
)
762-
return all(hasattr(select, x) for x in names)
763-
761+
)
764762

765763
# These are primarily fail-safe knobs for negatives. A True value does not
766764
# guarantee the given libc/syscall API will be used.
@@ -2090,7 +2088,7 @@ def _wait_pidfd(self, timeout):
20902088

20912089
def _wait_kqueue(self, timeout):
20922090
"""Wait for PID to terminate using kqueue(). macOS and BSD only."""
2093-
if not _can_use_kqueue():
2091+
if not _CAN_USE_KQUEUE:
20942092
return False
20952093
try:
20962094
kq = select.kqueue()

Lib/test/test_subprocess.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4116,13 +4116,13 @@ def test_wait_pidfd_open_error(self):
41164116
self.assert_fast_waitpid_error("os.pidfd_open")
41174117

41184118
@unittest.skipIf(
4119-
not subprocess._can_use_kqueue(), reason="macOS / BSD only"
4119+
not subprocess._CAN_USE_KQUEUE, reason="macOS / BSD only"
41204120
)
41214121
def test_wait_kqueue_error(self):
41224122
self.assert_fast_waitpid_error("select.kqueue")
41234123

41244124
@unittest.skipIf(
4125-
not subprocess._can_use_kqueue(), reason="macOS / BSD only"
4125+
not subprocess._CAN_USE_KQUEUE, reason="macOS / BSD only"
41264126
)
41274127
def test_kqueue_control_error(self):
41284128
# Emulate a case where kqueue.control() fails. _busy_wait()
@@ -4167,7 +4167,7 @@ def test_pidfd_open_race(self):
41674167
self.assert_wait_race_condition("os.pidfd_open", os.pidfd_open)
41684168

41694169
@unittest.skipIf(
4170-
not subprocess._can_use_kqueue(), reason="macOS / BSD only"
4170+
not subprocess._CAN_USE_KQUEUE, reason="macOS / BSD only"
41714171
)
41724172
def test_kqueue_race(self):
41734173
self.assert_wait_race_condition("select.kqueue", select.kqueue)

0 commit comments

Comments
 (0)