[ 
https://issues.apache.org/jira/browse/SPARK-45417?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Chungmin Lee updated SPARK-45417:
---------------------------------
    Description: 
Repro:

{code:java}
# repro.py
from multiprocessing.pool import ThreadPool
from pyspark import inheritable_thread_target
from pyspark.sql import SparkSession

spark = SparkSession.builder.appName("Test").getOrCreate()
spark.sparkContext.setLogLevel("ERROR")

def f(i, spark):
    print(f"{i} spark = {spark}")
    print(f"{i} active session = {SparkSession.getActiveSession()}")
    print(f"{i} local property foo = 
{spark.sparkContext.getLocalProperty('foo')}")
    spark = SparkSession.builder.appName("Test").getOrCreate()
    print(f"{i} spark = {spark}")
    print(f"{i} active session = {SparkSession.getActiveSession()}")

pool = ThreadPool(4)
spark.sparkContext.setLocalProperty("foo", "bar")
pool.starmap(inheritable_thread_target(f), [(i, spark) for i in range(4)]){code}

Run as: {{./bin/spark-submit repro.py}}

{{getOrCreate()}} doesn't set the active session either. The only way is 
calling the Java function directly: 
{{spark._jsparkSession.setActiveSession(spark._jsparkSession)}}.

 

  was:
Repro:

{code:java}
from multiprocessing.pool import ThreadPool
from pyspark import inheritable_thread_target
from pyspark.sql import SparkSession

spark = SparkSession.builder.appName("Test").getOrCreate()
spark.sparkContext.setLogLevel("ERROR")

def f(i, spark):
    print(f"{i} spark = {spark}")
    print(f"{i} active session = {SparkSession.getActiveSession()}")
    print(f"{i} local property foo = 
{spark.sparkContext.getLocalProperty('foo')}")
    spark = SparkSession.builder.appName("Test").getOrCreate()
    print(f"{i} spark = {spark}")
    print(f"{i} active session = {SparkSession.getActiveSession()}")

pool = ThreadPool(4)
spark.sparkContext.setLocalProperty("foo", "bar")
pool.starmap(inheritable_thread_target(f), [(i, spark) for i in range(4)]){code}

{{getOrCreate()}} doesn't set the active session either. The only way is 
calling the Java function directly: 
{{spark._jsparkSession.setActiveSession(spark._jsparkSession)}}.

 


> Make InheritableThread inherit the active session
> -------------------------------------------------
>
>                 Key: SPARK-45417
>                 URL: https://issues.apache.org/jira/browse/SPARK-45417
>             Project: Spark
>          Issue Type: Bug
>          Components: PySpark
>    Affects Versions: 3.5.0
>            Reporter: Chungmin Lee
>            Priority: Major
>
> Repro:
> {code:java}
> # repro.py
> from multiprocessing.pool import ThreadPool
> from pyspark import inheritable_thread_target
> from pyspark.sql import SparkSession
> spark = SparkSession.builder.appName("Test").getOrCreate()
> spark.sparkContext.setLogLevel("ERROR")
> def f(i, spark):
>     print(f"{i} spark = {spark}")
>     print(f"{i} active session = {SparkSession.getActiveSession()}")
>     print(f"{i} local property foo = 
> {spark.sparkContext.getLocalProperty('foo')}")
>     spark = SparkSession.builder.appName("Test").getOrCreate()
>     print(f"{i} spark = {spark}")
>     print(f"{i} active session = {SparkSession.getActiveSession()}")
> pool = ThreadPool(4)
> spark.sparkContext.setLocalProperty("foo", "bar")
> pool.starmap(inheritable_thread_target(f), [(i, spark) for i in 
> range(4)]){code}
> Run as: {{./bin/spark-submit repro.py}}
> {{getOrCreate()}} doesn't set the active session either. The only way is 
> calling the Java function directly: 
> {{spark._jsparkSession.setActiveSession(spark._jsparkSession)}}.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to