[Python-checkins] gh-106238: Handle KeyboardInterrupt during logging._acquireLock() (GH-106239)

vsajip webhook-mailer at python.org
Thu Jul 6 03:02:25 EDT 2023


https://github.com/python/cpython/commit/99b00efd5edfd5b26bf9e2a35cbfc96277fdcbb1
commit: 99b00efd5edfd5b26bf9e2a35cbfc96277fdcbb1
branch: main
author: Ariel Eizenberg <ariel.eizenberg at gmail.com>
committer: vsajip <vinay_sajip at yahoo.co.uk>
date: 2023-07-06T08:02:22+01:00
summary:

gh-106238: Handle KeyboardInterrupt during logging._acquireLock() (GH-106239)

Co-authored-by: Ariel Eizenberg <ariel.eizenberg at pagaya.com>

files:
A Misc/NEWS.d/next/Library/2023-06-29-12-40-52.gh-issue-106238.VulKb9.rst
M Lib/logging/__init__.py

diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index ba2ed44b09507..fe2039af0334a 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -238,7 +238,11 @@ def _acquireLock():
     This should be released with _releaseLock().
     """
     if _lock:
-        _lock.acquire()
+        try:
+            _lock.acquire()
+        except BaseException:
+            _lock.release()
+            raise
 
 def _releaseLock():
     """
diff --git a/Misc/NEWS.d/next/Library/2023-06-29-12-40-52.gh-issue-106238.VulKb9.rst b/Misc/NEWS.d/next/Library/2023-06-29-12-40-52.gh-issue-106238.VulKb9.rst
new file mode 100644
index 0000000000000..52e78382fd618
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-06-29-12-40-52.gh-issue-106238.VulKb9.rst
@@ -0,0 +1 @@
+Fix rare concurrency bug in lock acquisition by the logging package.



More information about the Python-checkins mailing list