From 38e9a5e02737a6df6c08434dbcc17aa2ed749055 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Moreno Date: Thu, 6 Feb 2025 13:27:31 +0100 Subject: [PATCH 1/2] Remove custom createLock method in BaseLogHandler This patch removes the override of createLock method so this class will use the default logging.Handler method. The tests are failing for python 3.13 because in this version there's a direct usage of self.lock instead of calling self.acquire(): https://github.com/python/cpython/blob/3.13/Lib/logging/__init__.py#L1025-L1026 --- .../opencensus/ext/azure/log_exporter/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py index 14e228d06..9565639c6 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py @@ -102,9 +102,6 @@ def close(self, timeout=None): self._worker.stop(timeout) super(BaseLogHandler, self).close() - def createLock(self): - self.lock = None - def emit(self, record): self._queue.put(record, block=False) From f068b92211774794efd4f1e204058f0b141e3e44 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Moreno Date: Wed, 30 Apr 2025 09:44:28 +0200 Subject: [PATCH 2/2] Set DummyLock to BaseLogHandler This patch adds a DummyLock to do not synchronising handling, as suggested in the comment: https://github.com/census-instrumentation/opencensus-python/pull/1248#issuecomment-2840942763 --- .../ext/azure/log_exporter/__init__.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py index 9565639c6..ac1d5300c 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py @@ -41,6 +41,27 @@ __all__ = ['AzureEventHandler', 'AzureLogHandler'] +class DummyLock: + """ + Implements the threading.Lock interface and do nothing + """ + + def __enter__(self): + return self + + def __exit__(self, *args): + return self + + def acquire(self, *args, **kwargs): + pass + + def release(self): + pass + + def _at_fork_reinit(self): + pass + + class BaseLogHandler(logging.Handler): def __init__(self, **options): @@ -102,6 +123,10 @@ def close(self, timeout=None): self._worker.stop(timeout) super(BaseLogHandler, self).close() + def createLock(self): + # not synchronising handling + self.lock = DummyLock() + def emit(self, record): self._queue.put(record, block=False)