-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-41833: threading.Thread now uses the target name #22357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -745,10 +745,9 @@ class BrokenBarrierError(RuntimeError): | |||
|
||||
|
||||
# Helper to generate new thread names | ||||
_counter = _count().__next__ | ||||
_counter() # Consume 0 so first non-main thread has id 1. | ||||
def _newname(template="Thread-%d"): | ||||
return template % _counter() | ||||
_counter = _count(1).__next__ | ||||
def _newname(name_template): | ||||
return name_template % _counter() | ||||
|
||||
# Active thread administration | ||||
_active_limbo_lock = _allocate_lock() | ||||
|
@@ -800,8 +799,19 @@ class is implemented. | |||
assert group is None, "group argument must be None for now" | ||||
if kwargs is None: | ||||
kwargs = {} | ||||
if name: | ||||
name = str(name) | ||||
if not name: | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to avoid empty thread name, and so I check that the result of str(name) is non-empty. Do you think that it's not worth it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current code allows to set an empty name, and with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Serhiy's suggestion, if someone uses an empty string it was probably intentional. I don't think it's worth trying to catch it. |
||||
name = _newname("Thread-%d") | ||||
if target is not None: | ||||
try: | ||||
target_name = target.__name__ | ||||
name += f" ({target_name})" | ||||
except AttributeError: | ||||
pass | ||||
|
||||
self._target = target | ||||
self._name = str(name or _newname()) | ||||
self._name = name | ||||
self._args = args | ||||
self._kwargs = kwargs | ||||
if daemon is not None: | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The :class:`threading.Thread` constructor now uses the target name if the | ||
*target* argument is specified but the *name* argument is omitted. |
Uh oh!
There was an error while loading. Please reload this page.