You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2026/02/08 22:18:53 UTC
(spark) branch master updated: [SPARK-55404][PYTHON] Always raise KeyboardInterrupt from SIGINT handler
This is an automated email from the ASF dual-hosted git repository.
gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 4c336897859c [SPARK-55404][PYTHON] Always raise KeyboardInterrupt from SIGINT handler
4c336897859c is described below
commit 4c336897859c3b03b95bb156d6d2b07737b7b3b4
Author: Tian Gao <ga...@hotmail.com>
AuthorDate: Mon Feb 9 07:18:42 2026 +0900
[SPARK-55404][PYTHON] Always raise KeyboardInterrupt from SIGINT handler
### What changes were proposed in this pull request?
In SIGINT handler, even if `cancelAllJobs()` raised an exception, we should keep raising KeyboardInterrupt()
### Why are the changes needed?
We should make sure users can Ctrl+C out of the program. `self.cancelAllJobs()` can raise an exception (for example, `self._jsc` might be `None` at that point and it could raise an `AttributeError`). `KeyboardInterrupt()` is a `BaseException` instead of `Exception` just to make sure it can propagate through a lot of `Exception` catch check. This makes sure that in most cases our users can send a SIGINT and get out of the program.
### Does this PR introduce _any_ user-facing change?
Well yes they can Ctrl+C out now - but it should not be a big deal, more like a bug fix.
### How was this patch tested?
CI should pass.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #54187 from gaogaotiantian/sig-handler-fix.
Authored-by: Tian Gao <ga...@hotmail.com>
Signed-off-by: Hyukjin Kwon <gu...@apache.org>
---
python/pyspark/core/context.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/python/pyspark/core/context.py b/python/pyspark/core/context.py
index 54e955318caa..78cf7f141312 100644
--- a/python/pyspark/core/context.py
+++ b/python/pyspark/core/context.py
@@ -405,8 +405,10 @@ class SparkContext:
# create a signal handler which would be invoked on receiving SIGINT
def signal_handler(signal: Any, frame: Any) -> NoReturn:
- self.cancelAllJobs()
- raise KeyboardInterrupt()
+ try:
+ self.cancelAllJobs()
+ finally:
+ raise KeyboardInterrupt()
# see http://stackoverflow.com/questions/23206787/
if isinstance(
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org