TypeError: 'NoneType' object is not callable in __del__() when exiting

未關閉 適合新手
#2,002 0 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
70/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python
領域
backend

研究方向

尋找 Llama 類別的定義,它可能位於 llama.py 之類的檔案中,或位於類似的核心模組中。找到它的 del 方法。修正方式是將 self.close() 呼叫包在 try-except 區塊中,以忽略例外。建立一個會建立模型實例並結束的簡單指令碼進行測試,確保不會出現 TypeError。

由索引模型根據 Issue 內容生成。

描述

Prerequisites

  • I am running the latest code.
  • I followed the README.md.
  • I searched open/closed issues.
  • This is a reproducible error and fix.

Expected Behavior

When the model is closed or Python exits, it should clean up resources quietly.

Current Behavior

When using Llama(...), a crash occurs on exit:

TypeError: 'NoneType' object is not callable

This happens inside __del__() when it tries to close internal objects (e.g., ExitStack or model context) that are already None.

Environment and Context

  • Windows 11
  • Python 3.11.3
  • llama-cpp-python version: 0.3.8
  • Using quantized GGUF model via Llama(...)

Steps to Reproduce

  1. Load model via Llama(model_path=..., ...)
  2. Let script exit
  3. Observe destructor crash in logs

Recommended Fix

Wrap close() call in __del__() like so:

def __del__(self):
    try:
        self.close()
    except Exception:
        pass
主要語言
Python
星號
10.6k
分支
1.5k
平均合併
23 分鐘
30 天內合併 PR
1

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

abetlen/llama-cpp-python 的其他 Issue

查看 abetlen/llama-cpp-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。