From c5b803c87c0bf709b72585475be88acf6bac88a5 Mon Sep 17 00:00:00 2001 From: "Paul J. Dorn" Date: Sun, 12 May 2024 23:54:38 +0200 Subject: [PATCH] fcntl(fd, O_NONBLOCK) => os.set_blocking(fd, False) --- .github/workflows/tox.yml | 2 +- appveyor.yml | 2 +- gunicorn/util.py | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 759800eb1..8fcf95b24 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -19,7 +19,7 @@ jobs: - ubuntu-latest # not defaulting to macos-latest: Python <= 3.9 was missing from macos-14 @ arm64 - macos-13 - # Not testing Windows, because tests need Unix-only fcntl, grp, pwd, etc. + # Not testing Windows, because tests need Unix-only non-blocking pipes, grp, pwd, etc. python-version: # CPython <= 3.7 is EoL since 2023-06-27 - "3.7" diff --git a/appveyor.yml b/appveyor.yml index 3cf11f0e9..505193911 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,7 @@ environment: #- TOXENV: run-entrypoint # PYTHON: "C:\\Python38-x64" # Windows is not ready for testing!!! - # Python's fcntl, grp, pwd, os.geteuid(), and socket.AF_UNIX are all Unix-only. + # Python's non-blocking pipes, grp, pwd, os.geteuid(), and socket.AF_UNIX are all Unix-only. #- TOXENV: py35 # PYTHON: "C:\\Python35-x64" #- TOXENV: py36 diff --git a/gunicorn/util.py b/gunicorn/util.py index 70c6c5463..fdb6a2aa0 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -4,7 +4,6 @@ import ast import email.utils import errno -import fcntl import html import importlib import inspect @@ -258,8 +257,10 @@ def close_on_exec(fd): def set_non_blocking(fd): - flags = fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK - fcntl.fcntl(fd, fcntl.F_SETFL, flags) + # available since Python 3.5, equivalent to either: + # ioctl(fd, FIONBIO) + # fcntl(fd, fcntl.F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) + os.set_blocking(fd, False) def close(sock):