[issue13550] Rewrite logging hack of the threading module

STINNER Victor report at bugs.python.org
Wed Dec 7 23:40:27 CET 2011

New submission from STINNER Victor <victor.stinner at haypocalc.com>:

The threading module uses an hack to log actions to help debugging. The log depends on 3 flags: __debug__, threading._VERBOSE and a verbose attribute (each threading class has such attribute). By default, _note() is always called but does nothing: it checks the verbose attribute and return if the flag is False.

Attached threading_note.patch only calls _note() if verbose is True to avoid a Python function call (which is slow in CPython). It avoids also a _Verbose parent class and pass the verbose flag to subobjects (e.g. Semaphore sets verbose argument of its Condition object).

I don't think that it is really useful to be able to enable/disable logs on only one threading object, so it is maybe simpler to have only one global flag (instead of 3 flags): threading._VERBOSE. Attached threading_note_global.patch replaces _note() method by a function, remove _Verbose class and the _verbose attribute, and only call _note() if _VERBOSE is True.

_VERBOSE and verbose arguments are undocumented and not tested, so I hope nobody relies on their API ;-)

components: Library (Lib)
files: threading_note.patch
keywords: patch
messages: 149001
nosy: haypo
priority: normal
severity: normal
status: open
title: Rewrite logging hack of the threading module
versions: Python 3.3
Added file: http://bugs.python.org/file23869/threading_note.patch

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list