From 4f98831b9fdd3883fcbe39fd31bffd1a331ebf5d Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 8 Dec 2024 15:10:31 +0000 Subject: [PATCH 1/2] Adjust logging lock handling for Python 3.13 https://github.com/python/cpython/pull/109462 removed `logging._acquireLock`. Fortunately, https://github.com/python/cpython/pull/3385 simplified lock creation so that `with logging._lock:` is sufficient; that PR made it into Python 3.7, which is already pastescript's minimum Python requirement. --- paste/script/util/logging_config.py | 27 ++++++++++----------------- tests/test_logging_config.py | 20 ++++---------------- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/paste/script/util/logging_config.py b/paste/script/util/logging_config.py index 8b51eca..8cba1ec 100644 --- a/paste/script/util/logging_config.py +++ b/paste/script/util/logging_config.py @@ -91,16 +91,13 @@ def fileConfig(fname, defaults=None): formatters = _create_formatters(cp) # critical section - logging._acquireLock() - try: + with logging._lock: logging._handlers.clear() if hasattr(logging, '_handlerList'): del logging._handlerList[:] # Handlers add themselves to logging._handlers handlers = _install_handlers(cp, formatters) _install_loggers(cp, handlers) - finally: - logging._releaseLock() def _resolve(name): @@ -327,9 +324,8 @@ class ConfigSocketReceiver(ThreadingTCPServer): def __init__(self, host='localhost', port=DEFAULT_LOGGING_CONFIG_PORT, handler=None): ThreadingTCPServer.__init__(self, (host, port), handler) - logging._acquireLock() - self.abort = 0 - logging._releaseLock() + with logging._lock: + self.abort = 0 self.timeout = 1 def serve_until_stopped(self): @@ -341,16 +337,14 @@ def serve_until_stopped(self): self.timeout) if rd: self.handle_request() - logging._acquireLock() - abort = self.abort - logging._releaseLock() + with logging._lock: + abort = self.abort def serve(rcvr, hdlr, port): server = rcvr(port=port, handler=hdlr) global _listener - logging._acquireLock() - _listener = server - logging._releaseLock() + with logging._lock: + _listener = server server.serve_until_stopped() return threading.Thread(target=serve, @@ -363,7 +357,6 @@ def stopListening(): """ global _listener if _listener: - logging._acquireLock() - _listener.abort = 1 - _listener = None - logging._releaseLock() + with logging._lock: + _listener.abort = 1 + _listener = None diff --git a/tests/test_logging_config.py b/tests/test_logging_config.py index 1f82130..4a154af 100644 --- a/tests/test_logging_config.py +++ b/tests/test_logging_config.py @@ -120,14 +120,11 @@ def test4(): conf = globals()['config%d' % i] sys.stdout.write('config%d: ' % i) loggerDict = logging.getLogger().manager.loggerDict - logging._acquireLock() - try: + with logging._lock: saved_handlers = logging._handlers.copy() if hasattr(logging, '_handlerList'): saved_handler_list = logging._handlerList[:] saved_loggers = loggerDict.copy() - finally: - logging._releaseLock() try: fn = tempfile.mktemp(".ini") f = open(fn, "w") @@ -146,8 +143,7 @@ def test4(): message('ok.') os.remove(fn) finally: - logging._acquireLock() - try: + with logging._lock: logging._handlers.clear() logging._handlers.update(saved_handlers) if hasattr(logging, '_handlerList'): @@ -155,8 +151,6 @@ def test4(): loggerDict = logging.getLogger().manager.loggerDict loggerDict.clear() loggerDict.update(saved_loggers) - finally: - logging._releaseLock() #---------------------------------------------------------------------------- # Test 5 @@ -196,14 +190,11 @@ def formatException(self, ei): def test5(): loggerDict = logging.getLogger().manager.loggerDict - logging._acquireLock() - try: + with logging._lock: saved_handlers = logging._handlers.copy() if hasattr(logging, '_handlerList'): saved_handler_list = logging._handlerList[:] saved_loggers = loggerDict.copy() - finally: - logging._releaseLock() try: fn = tempfile.mktemp(".ini") f = open(fn, "w") @@ -218,8 +209,7 @@ def test5(): hdlr = logging.getLogger().handlers[0] logging.getLogger().handlers.remove(hdlr) finally: - logging._acquireLock() - try: + with logging._lock: logging._handlers.clear() logging._handlers.update(saved_handlers) if hasattr(logging, '_handlerList'): @@ -227,5 +217,3 @@ def test5(): loggerDict = logging.getLogger().manager.loggerDict loggerDict.clear() loggerDict.update(saved_loggers) - finally: - logging._releaseLock() From ae87d35301574e600fa390ad7e998ebdc72f5757 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 8 Dec 2024 15:14:14 +0000 Subject: [PATCH 2/2] Document Python 3.13 support --- .github/workflows/tests.yaml | 2 ++ setup.py | 1 + tox.ini | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 6952937..d635532 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -21,6 +21,8 @@ jobs: toxenv: py311 - python: "3.12" toxenv: py312 + - python: "3.13" + toxenv: py313 name: ${{ matrix.toxenv }} on Python ${{ matrix.python }} steps: - uses: actions/checkout@v4 diff --git a/setup.py b/setup.py index 21fb0da..515672b 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,7 @@ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules", diff --git a/tox.ini b/tox.ini index 285158e..8543b08 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py{37,38,39,310,311,312}, pypy, pypy3 +envlist = py{37,38,39,310,311,312,313}, pypy, pypy3 [testenv] deps =