Github user ahirreddy commented on a diff in the pull request:
https://github.com/apache/spark/pull/541#discussion_r11976632
--- Diff: core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala
---
@@ -110,13 +110,35 @@ private[spark] class PythonRDD[T: ClassTag](
}
}.start()
+ // Necessary to distinguish between a task that has failed and a task
that is finished
+ @volatile var success: Boolean = false
+
+ // It is necessary to have a monitor thread for python workers if the
user cancel's with
+ // interrupts disabled. In that case we will need to explicitly kill
the worker, otherwise the
+ // threads can block indefinetly.
+ new Thread(s"Worker Monitor for $pythonExec") {
+ override def run() {
+ // Kill the worker if it is interrupted or completed
+ // When a python task completes, the context is always set to
interupted
+ while (!context.interrupted) {
+ Thread.sleep(2000)
+ }
+ if (!success) {
+ Try(env.destroyPythonWorker(pythonExec, envVars.toMap))
+ }
+ }
+ }.start()
+
/*
* Partial fix for SPARK-1019: Attempts to stop reading the input
stream since
* other completion callbacks might invalidate the input. Because
interruption
* is not synchronous this still leaves a potential race where the
interruption is
* processed only after the stream becomes invalid.
*/
- context.addOnCompleteCallback(() => context.interrupted = true)
+ context.addOnCompleteCallback{ () =>
+ success = true // Indicate that the task has completed successfully
+ context.interrupted = true
--- End diff --
Yeah, I think that's there to address another issue. The ```success``` flag
is to work around that since now ```context.interupted``` can mean either
interrupted or successful.
---
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.
---