aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/pyspark/context.py7
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