Skip to content

Commit 15563bf

Browse files
author
SamoraHunter
committed
Fix CatBoost timeout handling: treat KeyboardInterrupt as signal artifact
CatBoost interprets SIGALRM (used for timeouts) as a KeyboardInterrupt. This change catches KeyboardInterrupt specifically for CatBoost models and treats it as a timeout to prevent pipeline crashes.
1 parent 1bc3bbb commit 15563bf

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

ml_grid/pipeline/grid_search_cross_validate.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,18 @@ def __init__(
578578
failed = "Timeout"
579579
scores = default_scores
580580

581+
except KeyboardInterrupt:
582+
if "catboost" in method_name.lower():
583+
self.logger.warning(
584+
"KeyboardInterrupt detected during hyperparameter search. "
585+
"This is likely a signal handling artifact (e.g. from CatBoost) triggered by the timeout. "
586+
"Treating as a timeout."
587+
)
588+
failed = "KeyboardInterrupt"
589+
scores = default_scores
590+
else:
591+
raise
592+
581593
except Exception as e:
582594
if "dual coefficients or intercepts are not finite" in str(e):
583595
self.logger.warning(
@@ -919,6 +931,18 @@ def __init__(
919931
failed = "Timeout"
920932
scores = default_scores
921933

934+
except KeyboardInterrupt:
935+
if "catboost" in method_name.lower():
936+
self.logger.warning(
937+
"KeyboardInterrupt detected during cross-validation. "
938+
"This is likely a signal handling artifact (e.g. from CatBoost) triggered by the timeout. "
939+
"Treating as a timeout."
940+
)
941+
failed = "KeyboardInterrupt"
942+
scores = default_scores
943+
else:
944+
raise
945+
922946
except Exception as e:
923947
# Catch any other general exceptions and log them
924948
self.logger.error(

0 commit comments

Comments
 (0)