Skip to content

gh-145242: Add early validation for target in Thread and Process#145243

Open
gourijain029-del wants to merge 2 commits intopython:mainfrom
gourijain029-del:fix-thread-target-traceback
Open

gh-145242: Add early validation for target in Thread and Process#145243
gourijain029-del wants to merge 2 commits intopython:mainfrom
gourijain029-del:fix-thread-target-traceback

Conversation

@gourijain029-del
Copy link

@gourijain029-del gourijain029-del commented Feb 26, 2026

his PR adds early validation for the

target
argument in the constructors of threading.Thread and multiprocessing.Process.

Changes
Early Validation: The

target
argument is now checked for callability within

init
. If a non-callable

target
is provided (and it is not

None
), a TypeError is raised immediately in the calling thread.
Improved Tracebacks: Previously, the validation would only fail deep within the library's internal

_bootstrap
or

start()
logic. By moving this check to the constructor, the resulting traceback now clearly points to the line where the

Thread
or

Process
object was instantiated, making it significantly easier for users to debug.
Group Argument Validation: Replaced internal assert group is None statements with explicit TypeError raises. This ensures consistent error reporting even when Python is run with optimizations (-O).
Unit Tests: Added

test_invalid_args
to both test_threading and test_multiprocessing to ensure correct behavior and prevent regressions.

@@ -0,0 +1 @@
Fix a segmentation fault in :func:`unicodedata.iter_graphemes` when the iterator is deallocated after being cleared by the garbage collector.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have unrelated changes on this branch.

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert unrelated changes.

@bedevere-app
Copy link

bedevere-app bot commented Feb 28, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants