HyukjinKwon commented on a change in pull request #32399:
URL: https://github.com/apache/spark/pull/32399#discussion_r623528470
##########
File path: python/pyspark/util.py
##########
@@ -263,6 +264,46 @@ def _parse_memory(s):
return int(float(s[:-1]) * units[s[-1].lower()])
+def _on_inheritable_thread_start():
+ from pyspark import SparkContext
+ sc = SparkContext._active_spark_context
+ if isinstance(sc._gateway, ClientServer):
+ # Here's when the pinned-thread mode (PYSPARK_PIN_THREAD) is on.
+ properties = sc._jsc.sc().getLocalProperties().clone()
+ sc._jsc.sc().setLocalProperties(properties)
+
+
+def _on_inheritable_thread_stop():
+ from pyspark import SparkContext
+ sc = SparkContext._active_spark_context
+ if isinstance(SparkContext._gateway, ClientServer):
+ thread_connection =
sc._jvm._gateway_client.thread_connection.connection()
+ if thread_connection is not None:
+ connections = sc._jvm._gateway_client.deque
+
+ # Reuse the lock for Py4J in PySpark
+ with SparkContext._lock:
+ for i in range(len(connections)):
+ if connections[i] is thread_connection:
+ connections[i].close()
+ del connections[i]
+ break
+ else:
+ # Just in case the connection was not closed but removed
from the queue.
+ thread_connection.close()
+
+
+def inheritable_thread(f):
Review comment:
I think it should also show some example about how to use
--
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]