Repository: spark Updated Branches: refs/heads/master 149472a01 -> 2e572c413
[SPARK-8170] [PYTHON] Add signal handler to trap Ctrl-C in pyspark and cancel all running jobs This patch adds a signal handler to trap Ctrl-C and cancels running job. Author: Ashwin Shankar <[email protected]> Closes #9033 from ashwinshankar77/master. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/2e572c41 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/2e572c41 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/2e572c41 Branch: refs/heads/master Commit: 2e572c4135c3f5ad3061c1f58cdb8a70bed0a9d3 Parents: 149472a Author: Ashwin Shankar <[email protected]> Authored: Mon Oct 12 11:06:21 2015 -0700 Committer: Davies Liu <[email protected]> Committed: Mon Oct 12 11:06:21 2015 -0700 ---------------------------------------------------------------------- python/pyspark/context.py | 7 +++++++ 1 file changed, 7 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/2e572c41/python/pyspark/context.py ---------------------------------------------------------------------- diff --git a/python/pyspark/context.py b/python/pyspark/context.py index a0a1ccb..4969d85 100644 --- a/python/pyspark/context.py +++ b/python/pyspark/context.py @@ -19,6 +19,7 @@ from __future__ import print_function import os import shutil +import signal import sys from threading import Lock from tempfile import NamedTemporaryFile @@ -217,6 +218,12 @@ class SparkContext(object): else: self.profiler_collector = None + # create a signal handler which would be invoked on receiving SIGINT + def signal_handler(signal, frame): + self.cancelAllJobs() + + signal.signal(signal.SIGINT, signal_handler) + def _initialize_context(self, jconf): """ Initialize SparkContext in function to allow subclass specific initialization --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
