Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,19 @@ private[spark] class StreamingPythonRunner(

envVars.put("SPARK_AUTH_SOCKET_TIMEOUT", authSocketTimeout.toString)
envVars.put("SPARK_BUFFER_SIZE", bufferSize.toString)
conf.set(PYTHON_USE_DAEMON, false)
envVars.put("SPARK_CONNECT_LOCAL_URL", connectUrl)

val (worker, _) = env.createPythonWorker(
pythonExec, workerModule, envVars.asScala.toMap)
pythonWorker = Some(worker)
val prevConf = conf.get(PYTHON_USE_DAEMON)
conf.set(PYTHON_USE_DAEMON, false)
try {
val (worker, _) = env.createPythonWorker(
pythonExec, workerModule, envVars.asScala.toMap)
pythonWorker = Some(worker)
} finally {
conf.set(PYTHON_USE_DAEMON, prevConf)
}

val stream = new BufferedOutputStream(worker.getOutputStream, bufferSize)
val stream = new BufferedOutputStream(pythonWorker.get.getOutputStream, bufferSize)
val dataOut = new DataOutputStream(stream)

// TODO(SPARK-44461): verify python version
Expand All @@ -87,7 +92,8 @@ private[spark] class StreamingPythonRunner(
dataOut.write(command.toArray)
dataOut.flush()

val dataIn = new DataInputStream(new BufferedInputStream(worker.getInputStream, bufferSize))
val dataIn = new DataInputStream(
new BufferedInputStream(pythonWorker.get.getInputStream, bufferSize))

val resFromPython = dataIn.readInt()
logInfo(s"Runner initialization returned $resFromPython")
Expand All @@ -100,7 +106,13 @@ private[spark] class StreamingPythonRunner(
*/
def stop(): Unit = {
pythonWorker.foreach { worker =>
SparkEnv.get.destroyPythonWorker(pythonExec, workerModule, envVars.asScala.toMap, worker)
val prevConf = conf.get(PYTHON_USE_DAEMON)
conf.set(PYTHON_USE_DAEMON, false)
try {
SparkEnv.get.destroyPythonWorker(pythonExec, workerModule, envVars.asScala.toMap, worker)
} finally {
conf.set(PYTHON_USE_DAEMON, prevConf)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is needed as env.destroyPythonWorker won't refer conf.

}
}
}