Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 401edd6

Browse files
committed
Issue #4188: Avoid creating dummy thread objects when logging operations
from the threading module (with the internal verbose flag activated).
1 parent 988dbd7 commit 401edd6

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Lib/threading.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ def __init__(self, verbose=None):
5555
def _note(self, format, *args):
5656
if self._verbose:
5757
format = format % args
58-
format = "%s: %s\n" % (
59-
current_thread().name, format)
58+
# Issue #4188: calling current_thread() can incur an infinite
59+
# recursion if it has to create a DummyThread on the fly.
60+
ident = _get_ident()
61+
try:
62+
name = _active[ident].name
63+
except KeyError:
64+
name = "<OS thread %d>" % ident
65+
format = "%s: %s\n" % (name, format)
6066
_sys.stderr.write(format)
6167

6268
else:

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Core and Builtins
2020
Library
2121
-------
2222

23+
- Issue #4188: Avoid creating dummy thread objects when logging operations
24+
from the threading module (with the internal verbose flag activated).
25+
2326
- Issue #10711: Remove HTTP 0.9 support from http.client. The ``strict``
2427
parameter to HTTPConnection and friends is deprecated.
2528

0 commit comments

Comments
 (0)