1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
Description: Do not use logging._aquirelock()
The logging._aquirelock() was a private thing that should have never
been used by this lib.
Author: Thomas Goirand <zigo@debian.org>
Forwarded: no
Bug-Debian: https://bugs.debian.org/1082227
Last-Update: 2024-09-23
Index: python-logutils/tests/test_dictconfig.py
===================================================================
--- python-logutils.orig/tests/test_dictconfig.py
+++ python-logutils/tests/test_dictconfig.py
@@ -6,6 +6,7 @@ from logutils.adapter import LoggerAdapt
from logutils.dictconfig import dictConfig, named_handlers_supported
from logutils.testing import TestHandler, Matcher
import sys
+import threading
import unittest
try:
@@ -37,9 +38,10 @@ class ConfigDictTest(unittest.TestCase):
def setUp(self):
self.logger = l = logging.getLogger()
self.adapter = LoggerAdapter(l, {})
+ self.lock = threading.Lock()
logger_dict = logging.getLogger().manager.loggerDict
- logging._acquireLock()
+ self.lock.acquire()
try:
self.saved_handlers = logging._handlers.copy()
self.saved_handler_list = logging._handlerList[:]
@@ -50,7 +52,7 @@ class ConfigDictTest(unittest.TestCase):
self.saved_level_to_name = logging._levelToName.copy()
self.saved_name_to_level = logging._nameToLevel.copy()
finally:
- logging._releaseLock()
+ self.lock.release()
self.root_logger = logging.getLogger("")
self.original_logging_level = self.root_logger.getEffectiveLevel()
@@ -58,7 +60,7 @@ class ConfigDictTest(unittest.TestCase):
def tearDown(self):
self.root_logger.setLevel(self.original_logging_level)
- logging._acquireLock()
+ self.lock.acquire()
try:
if hasattr(logging, '_levelNames'):
logging._levelNames.clear()
@@ -75,7 +77,7 @@ class ConfigDictTest(unittest.TestCase):
loggerDict.clear()
loggerDict.update(self.saved_loggers)
finally:
- logging._releaseLock()
+ self.lock.release()
message_num = 0
Index: python-logutils/logutils/dictconfig.py
===================================================================
--- python-logutils.orig/logutils/dictconfig.py
+++ python-logutils/logutils/dictconfig.py
@@ -4,6 +4,7 @@
import logging.handlers
import re
import sys
+import threading
import types
try:
@@ -290,7 +291,8 @@ class DictConfigurator(BaseConfigurator)
raise ValueError("Unsupported version: %s" % config['version'])
incremental = config.pop('incremental', False)
EMPTY_DICT = {}
- logging._acquireLock()
+ self.lock = threading.Lock()
+ self.lock.acquire()
try:
if incremental:
handlers = config.get('handlers', EMPTY_DICT)
@@ -431,7 +433,7 @@ class DictConfigurator(BaseConfigurator)
raise ValueError('Unable to configure root '
'logger: %s' % e)
finally:
- logging._releaseLock()
+ self.lock.release()
def configure_formatter(self, config):
"""Configure a formatter from a dictionary."""
|