-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-18274][ML][PYSPARK] Memory leak in PySpark JavaWrapper #15843
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a493c19
[SPARK-18274] Memory leak in PySpark StringIndexer
techaddict f25b099
change
techaddict 3d858a2
Fixing copy bug (#1)
jkbradley 28a940e
check if there is active_spark_context
techaddict dc5aee3
Merge branch 'master' into SPARK-18274
techaddict 01a80b9
nit: doc fix
techaddict a76a1fb
doc
techaddict d7848c8
Merge branch 'master' into SPARK-18274
techaddict ddad40b
Merge branch 'master' into SPARK-18274
techaddict 37e83e8
move del to javaparams
techaddict File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ def __init__(self, java_obj=None): | |
| super(JavaWrapper, self).__init__() | ||
| self._java_obj = java_obj | ||
|
|
||
| def __del__(self): | ||
| if SparkContext._active_spark_context: | ||
| SparkContext._active_spark_context._gateway.detach(self._java_obj) | ||
|
|
||
| @classmethod | ||
| def _create_from_java_class(cls, java_class, *args): | ||
| """ | ||
|
|
@@ -180,6 +184,25 @@ def __get_class(clazz): | |
| % stage_name) | ||
| return py_stage | ||
|
|
||
| def copy(self, extra=None): | ||
| """ | ||
| Creates a copy of this instance with the same uid and some | ||
| extra params. This implementation first calls Params.copy and | ||
| then make a copy of the companion Java pipeline component with | ||
| extra params. So both the Python wrapper and the Java model get | ||
|
||
| copied. | ||
|
|
||
| :param extra: Extra parameters to copy to the new instance | ||
| :return: Copy of this instance | ||
| """ | ||
| if extra is None: | ||
| extra = dict() | ||
| that = super(JavaParams, self).copy(extra) | ||
| if self._java_obj is not None: | ||
| that._java_obj = self._java_obj.copy(self._empty_java_param_map()) | ||
| that._transfer_params_to_java() | ||
| return that | ||
|
|
||
|
|
||
| @inherit_doc | ||
| class JavaEstimator(JavaParams, Estimator): | ||
|
|
@@ -256,21 +279,3 @@ def __init__(self, java_model=None): | |
| super(JavaModel, self).__init__(java_model) | ||
| if java_model is not None: | ||
| self._resetUid(java_model.uid()) | ||
|
|
||
| def copy(self, extra=None): | ||
| """ | ||
| Creates a copy of this instance with the same uid and some | ||
| extra params. This implementation first calls Params.copy and | ||
| then make a copy of the companion Java model with extra params. | ||
| So both the Python wrapper and the Java model get copied. | ||
|
|
||
| :param extra: Extra parameters to copy to the new instance | ||
| :return: Copy of this instance | ||
| """ | ||
| if extra is None: | ||
| extra = dict() | ||
| that = super(JavaModel, self).copy(extra) | ||
| if self._java_obj is not None: | ||
| that._java_obj = self._java_obj.copy(self._empty_java_param_map()) | ||
| that._transfer_params_to_java() | ||
| return that | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking if there is active spark context, got this error after
quit()inpyspark