[SPARK-35303][SPARK-35498][PYTHON][FOLLOW-UP] Copy local properties when starting the thread, and use inheritable thread in the current codebase #32962
+79
−39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR is a followup of #32429 and #32644.
I was thinking about creating separate PRs but decided to include all in this PR because it shares the same context, and should be easier to review together.
This PR includes:
InheritableThread
andinheritable_thread_target
in the current code base to prevent potential resource leak (since we enabled pinned thread mode by default now at [SPARK-35303][PYTHON] Enable pinned thread mode by default #32429)start
atInheritableThread
is called to mimic JVM behaviour. Previously it was copied whenInheritableThread
instance was created (related to [SPARK-35498][PYTHON] Add thread target wrapper API for pyspark pin thread mode #32644).inheritable_thread_target
(https://github.com/apache/spark/blob/master/python/pyspark/util.py#L308). More specifically, I missed one place that should enable pinned thread mode by default.Why are the changes needed?
To mimic the JVM behaviour about thread lifecycle
Does this PR introduce any user-facing change?
Ideally no. One possible case is that users use
InheritableThread
with pinned thread mode enabled.In this case, the local properties will be copied when starting the thread instead of defining the
InheritableThread
object.This is a small difference that wouldn't likely affect end users.
How was this patch tested?
Existing tests should cover this.