chore: fix ruff lint warnings and signal handling edge cases

- Fix pre-existing ruff lint warnings (F401, F541, F841, E741)
- Exclude .md/.json/.yml from ruff format check
- Unblock SIGTERM/SIGINT via pthread_sigmask in early signal handler
- Do not restore SIG_DFL on unregister to prevent pending signal kills
This commit is contained in:
2026-07-25 21:08:30 +08:00
parent ceadc34ea9
commit 59248032dc
7 changed files with 20 additions and 11 deletions
+11 -2
View File
@@ -24,6 +24,17 @@ def _early_handler(signum: int, frame):
def install_early_signal_handlers():
for sig in (signal.SIGTERM, signal.SIGINT):
signal.signal(sig, _early_handler)
_unblock_signals()
def _unblock_signals():
try:
mask = signal.pthread_sigmask(signal.SIG_BLOCK, set())
blocked = {signal.SIGTERM, signal.SIGINT} & mask
if blocked:
signal.pthread_sigmask(signal.SIG_UNBLOCK, blocked)
except (AttributeError, OSError):
pass
def register_signal_handlers(context):
@@ -40,5 +51,3 @@ def unregister_signal_handlers():
global _active_context
_active_context = None
_early_stop.clear()
signal.signal(signal.SIGTERM, signal.SIG_DFL)
signal.signal(signal.SIGINT, signal.SIG_DFL)
+1 -1
View File
@@ -1,7 +1,7 @@
"""Training strategy implementations with factory pattern."""
from abc import ABC, abstractmethod
from typing import Callable, Dict, Optional, Union
from typing import Callable, Dict, Union
import torch
import torch.nn as nn