Repository: incubator-toree
Updated Branches:
  refs/heads/master db30f7292 -> c2c095962


[TOREE-437] Establish alternate interrupt handler

Cell interrupts do not take place if Toree is running
in the background (typically due to its parent being
in the background). This PR adds support for the caller
of Toree to specify an alternate interrupt signal via the
environment variable TOREE_ALTERNATE_SIGINT - the value of
which should be the string indicating the alternate signal
name's suffix portion (e.g., "USR2" for SIGUSR2).

The common scenario would be to specify this env value in
the kernel.json's env: stanza when necessary ...

  "display_name": "Apache Toree - Scala",
  "env": {
    "DEFAULT_INTERPRETER": "Scala",
    "PYTHON_EXEC": "python",
    "__TOREE_SPARK_OPTS__": "",
    "__TOREE_OPTS__": "",
    "TOREE_ALTERNATE_SIGINT": "USR2",

If the value of TOREE_ALTERNATE_SIGINT is not recognized
as a valid signal name, a warning message will be logged,
but the kernel's launch will proceed:

17/09/11 08:44:37 [WARN] o.a.t.Main$$anon$1 - Error occurred
establishing alternate signal handler.  Value of
TOREE_ALTERNATE_SIGINT is probably bad: FOO.
Error: Unknown signal: FOO

Closes #140


Project: http://git-wip-us.apache.org/repos/asf/incubator-toree/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-toree/commit/c2c09596
Tree: http://git-wip-us.apache.org/repos/asf/incubator-toree/tree/c2c09596
Diff: http://git-wip-us.apache.org/repos/asf/incubator-toree/diff/c2c09596

Branch: refs/heads/master
Commit: c2c095962084d8725949f9a395dd0609f0c2a567
Parents: db30f72
Author: Kevin Bates <kevin.ba...@us.ibm.com>
Authored: Mon Sep 11 09:09:53 2017 -0700
Committer: Luciano Resende <lrese...@apache.org>
Committed: Wed Sep 13 07:30:18 2017 -0700

----------------------------------------------------------------------
 .../toree/boot/layer/HookInitialization.scala   | 23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/c2c09596/kernel/src/main/scala/org/apache/toree/boot/layer/HookInitialization.scala
----------------------------------------------------------------------
diff --git 
a/kernel/src/main/scala/org/apache/toree/boot/layer/HookInitialization.scala 
b/kernel/src/main/scala/org/apache/toree/boot/layer/HookInitialization.scala
index ae2c478..bf6cd0f 100644
--- a/kernel/src/main/scala/org/apache/toree/boot/layer/HookInitialization.scala
+++ b/kernel/src/main/scala/org/apache/toree/boot/layer/HookInitialization.scala
@@ -89,6 +89,29 @@ trait StandardHookInitialization extends HookInitialization {
         }
       }
     })
+    // Define handler for alternate signal that will be fired in cases where
+    // the caller is in a background process in order to interrupt
+    // cell operations - since SIGINT doesn't propagate in those cases.
+    // Like INT above except we don't need to deal with shutdown in
+    // repeated situations.
+    val altSigint = System.getenv("TOREE_ALTERNATE_SIGINT")
+    if (altSigint != null) {
+      try {
+        Signal.handle(new Signal(altSigint), new SignalHandler() {
+
+            def handle(sig: Signal) = {
+              logger.info("Resetting code execution due to interrupt!")
+              interpreter.interrupt()
+
+              // TODO: Cancel group representing current code execution
+              //sparkContext.cancelJobGroup()
+            }
+        })
+      } catch {
+        case e:Exception => logger.warn("Error occurred establishing alternate 
signal handler " +
+          "(TOREE_ALTERNATE_SIGINT = " + altSigint + ").  Error: " + 
e.getMessage )
+      }
+    }
   }
 
   private def registerShutdownHook(): Unit = {

Reply via email to