GitHub user BryanCutler opened a pull request:
https://github.com/apache/spark/pull/17195
[SPARK-19348][PYTHON] PySpark keyword_only decorator is not thread-safe
## What changes were proposed in this pull request?
The `@keyword_only` decorator in PySpark is not thread-safe. It writes
kwargs to a static class variable in the decorator, which is then retrieved
later in the class method as `_input_kwargs`. If multiple threads are
constructing the same class with different kwargs, it becomes a race condition
to read from the static class variable before it's overwritten. See
[SPARK-19348](https://issues.apache.org/jira/browse/SPARK-19348) for
reproduction code.
This change will write the kwargs to a member variable so that multiple
threads can operate on separate instances without the race condition. It does
not protect against multiple threads operating on a single instance, but that
is better left to the user to synchronize.
## How was this patch tested?
Added new unit tests for using the keyword_only decorator and a regression
test that verifies `_input_kwargs` can be overwritten from different class
instances.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/BryanCutler/spark
pyspark-keyword_only-threadsafe-SPARK-19348-2_0
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/17195.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #17195
----
commit 830d812ee924a8d08a801898bd6752eb3add1467
Author: Bryan Cutler <[email protected]>
Date: 2017-03-07T18:53:51Z
made keyword_only decorator thread-safe by saving _input_kwargs to self
commit 2e5a9e141b711a94f329a93b8f62de4559f678a4
Author: Bryan Cutler <[email protected]>
Date: 2017-03-07T19:32:45Z
updated _input_kwargs usage in pyspark-ml
commit 2f3838caf088bae1264107e5db24f928109ab7dd
Author: Bryan Cutler <[email protected]>
Date: 2017-03-07T18:55:22Z
added keyword_only tests, including a regression test
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]