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.

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.

2 participants