diff options
author | Ashwin Shankar <ashankar@netflix.com> | 2015-10-12 11:06:21 -0700 |
---|---|---|
committer | Davies Liu <davies.liu@gmail.com> | 2015-10-12 11:06:21 -0700 |
commit | 2e572c4135c3f5ad3061c1f58cdb8a70bed0a9d3 (patch) | |
tree | e704b7ed399aebe53d8bdbb298a737a9505b2063 | |
parent | 149472a01d12828c64b0a852982d48c123984182 (diff) | |
download | spark-2e572c4135c3f5ad3061c1f58cdb8a70bed0a9d3.tar.gz spark-2e572c4135c3f5ad3061c1f58cdb8a70bed0a9d3.tar.bz2 spark-2e572c4135c3f5ad3061c1f58cdb8a70bed0a9d3.zip |
[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 <ashankar@netflix.com>
Closes #9033 from ashwinshankar77/master.
-rw-r--r-- | python/pyspark/context.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/python/pyspark/context.py b/python/pyspark/context.py index a0a1ccbeef..4969d85f52 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 |