Skip to content

Commit 5ca5b5b

Browse files
committed
aquire logging lock using _lock context manager
Aquire the logging lock using the underlying _lock object from the logging module. As of python/cpython#3385, included in Python 3.7, this object an instance of threading.RLock whose use as a context manager with release being called when the block exits, see https://docs.python.org/3/library/threading.html#using-locks-conditions-and-semaphores-in-the-with-statement
1 parent 48ec6d4 commit 5ca5b5b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

conda/common/io.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,14 @@ def disable_logger(logger_name):
279279
logr = getLogger(logger_name)
280280
_lvl, _dsbld, _prpgt = logr.level, logr.disabled, logr.propagate
281281
null_handler = NullHandler()
282-
with _logger_lock():
282+
with logging._lock:
283283
logr.addHandler(null_handler)
284284
logr.setLevel(CRITICAL + 1)
285285
logr.disabled, logr.propagate = True, False
286286
try:
287287
yield
288288
finally:
289-
with _logger_lock():
289+
with logging._lock:
290290
logr.removeHandler(null_handler) # restore list logr.handlers
291291
logr.level, logr.disabled = _lvl, _dsbld
292292
logr.propagate = _prpgt
@@ -305,15 +305,15 @@ def stderr_log_level(level, logger_name=None):
305305
handler.name = "stderr"
306306
handler.setLevel(level)
307307
handler.setFormatter(_FORMATTER)
308-
with _logger_lock():
308+
with logging._lock:
309309
logr.setLevel(level)
310310
logr.handlers, logr.disabled, logr.propagate = [], False, False
311311
logr.addHandler(handler)
312312
logr.setLevel(level)
313313
try:
314314
yield
315315
finally:
316-
with _logger_lock():
316+
with logging._lock:
317317
logr.handlers, logr.level, logr.disabled = _hndlrs, _lvl, _dsbld
318318
logr.propagate = _prpgt
319319

@@ -354,7 +354,7 @@ def attach_stderr_handler(
354354
new_stderr_handler.addFilter(filter_)
355355

356356
# do the switch
357-
with _logger_lock():
357+
with logging._lock:
358358
if old_stderr_handler:
359359
logr.removeHandler(old_stderr_handler)
360360
logr.addHandler(new_stderr_handler)

0 commit comments

Comments
 (0)