TypeError: 'NoneType' object is not callable in __del__() when exiting
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
Research direction
Look for the Llama class definition, likely in a file like llama.py or a similar core module. Find its del method. The fix is to wrap the self.close() call in a try-except block to ignore exceptions. Test by creating a simple script that instantiates the model and exits, ensuring no TypeError appears.
Written by the indexing model from the issue text.
Description
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
- Load model via
Llama(model_path=..., ...) - Let script exit
- Observe destructor crash in logs
Recommended Fix
Wrap close() call in __del__() like so:
def __del__(self):
try:
self.close()
except Exception:
pass
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 1.5k
- Avg merge
- 23m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from abetlen/llama-cpp-python
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
abetlen/llama-cpp-python#2352 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
abetlen/llama-cpp-python#2211 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
abetlen/llama-cpp-python#2210 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
abetlen/llama-cpp-python#2145 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
abetlen/llama-cpp-python#2135 · 4 reactions ·
All issues in abetlen/llama-cpp-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100