From d5c307ae67f40ac996c492d557eed4e45eec0d91 Mon Sep 17 00:00:00 2001 From: haosenwang1018 Date: Wed, 25 Feb 2026 09:19:52 +0000 Subject: [PATCH] fix: replace bare except clauses with except Exception Bare `except:` catches BaseException including KeyboardInterrupt and SystemExit. Replaced 5 instances with `except Exception:`. --- nanochat/dataset.py | 2 +- nanochat/report.py | 4 ++-- scripts/base_train.py | 2 +- scripts/chat_sft.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nanochat/dataset.py b/nanochat/dataset.py index 602daed..5a558dc 100644 --- a/nanochat/dataset.py +++ b/nanochat/dataset.py @@ -95,7 +95,7 @@ def download_single_file(index): if os.path.exists(path): try: os.remove(path) - except: + except Exception: pass # Try a few times with exponential backoff: 2^attempt seconds if attempt < max_attempts: diff --git a/nanochat/report.py b/nanochat/report.py index 5e74b98..bc072e7 100644 --- a/nanochat/report.py +++ b/nanochat/report.py @@ -22,7 +22,7 @@ def run_command(cmd): if result.returncode == 0: return "" return None - except: + except Exception: return None def get_git_info(): @@ -237,7 +237,7 @@ def extract_timestamp(content, prefix): time_str = line.split(":", 1)[1].strip() try: return datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S") - except: + except Exception: pass return None diff --git a/scripts/base_train.py b/scripts/base_train.py index 24091b6..fc32a63 100644 --- a/scripts/base_train.py +++ b/scripts/base_train.py @@ -559,7 +559,7 @@ while True: if first_step_of_run: gc.collect() # manually collect a lot of garbage from setup gc.freeze() # immediately freeze all currently surviving objects and exclude them from GC - gc.disable() # nuclear intervention here: disable GC entirely except: + gc.disable() # nuclear intervention here: disable GC entirely except Exception: elif step % 5000 == 0: # every 5000 steps... gc.collect() # manually collect, just to be safe for very, very long runs diff --git a/scripts/chat_sft.py b/scripts/chat_sft.py index a783ed2..ad195cd 100644 --- a/scripts/chat_sft.py +++ b/scripts/chat_sft.py @@ -468,7 +468,7 @@ while True: if step == 1: gc.collect() # manually collect a lot of garbage from setup gc.freeze() # freeze all currently surviving objects and exclude them from GC - gc.disable() # disable GC entirely except: + gc.disable() # disable GC entirely except Exception: elif step % 5000 == 0: # every 5000 steps... gc.collect() # manually collect, just to be safe for very long runs