HyukjinKwon commented on a change in pull request #32399:
URL: https://github.com/apache/spark/pull/32399#discussion_r630128638



##########
File path: python/pyspark/util.py
##########
@@ -263,6 +264,69 @@ def _parse_memory(s):
     return int(float(s[:-1]) * units[s[-1].lower()])
 
 
+def is_pinned_thread_mode():
+    """
+    Return ``True`` when spark run under pinned thread mode.
+    """
+    from pyspark import SparkContext
+    return isinstance(SparkContext._gateway, ClientServer)
+
+
+def inheritable_thread_target(f):
+    """
+    Return thread target wrapper which is recommended to be used in PySpark 
when the
+    pinned thread mode is enabled. The wrapper function, before calling 
original
+    thread target, it inherits the inheritable properties specific
+    to JVM thread such as ``InheritableThreadLocal``.
+
+    Also, note that pinned thread mode does not close the connection from 
Python
+    to JVM when the thread is finished in the Python side. With this wrapper, 
Python
+    garbage-collects the Python thread instance and also closes the connection
+    which finishes JVM thread correctly.
+
+    When the pinned thread mode is off, it return the original ``f``.
+    :param f: the original thread target.
+
+    .. versionadded:: 3.1.0

Review comment:
       I wouldn't backport APIs unless it fixes something critical though. Also 
pinned thread mode is disabled by default. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to