Open
Description
Crash report
What happened?
I was testing some AI code with ollama and stumbled across a really weird crash.
The fact that it happens during an IndexError and a specific function has to be there leads me to believe that this is a CPython bug and not an ollama bug.
from ollama import chat
# Has to be here to segfault???
def colorSwitch(color):
print(color, end="", flush=True)
stream = chat(
model="llama3.2", # I think it works with any but this is what I used.
messages=[{"role": "user", "content": ""}],
options={"seed":0}, # Does not need this but I figured it would be helpful
stream=True,
)
# Any iteration works. I just simplified it down to this.
part = next(iter(stream))['message']['content']
temp = part.split("</think>", 1)
# Crash Here
temp[1]
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.13.2 (main, Feb 5 2025, 08:05:21) [GCC 14.2.1 20250128]
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
No status
Milestone
Relationships
Development
No branches or pull requests
Activity
picnixz commentedon Apr 11, 2025
What's the crash? please provide the traceback (shown on the terminal if possible) (not just the core dump).
Jacoblightning commentedon Apr 11, 2025
Sorry. Here is the python traceback. If you wanted a gdb or other traceback, let me know.
picnixz commentedon Apr 11, 2025
If possible yes, so that we know where the crash exactly happens. If possible, you can use
python -X faulthandler crasher.py
as well though I'm not sure if we're able to know more.Also, it might be that
ollama
is using the Python C API behind the scene (AFAIU,ollama
is written in Go and C but there are Python bindings, which may be the ones where the issue arise).[-]Segfault on IndexError under specific conditions[/-][+]SIGSEV following an `IndexError` when using `ollama`[/+]Jacoblightning commentedon Apr 11, 2025
Ah. It appears that it is an ollama issue after all. Ill raise it over there.
Jacoblightning commentedon Apr 11, 2025
@picnixz So, I just checked and it appears that ollama-python is pure python. (Ofc I realized this after I made the issue.) Would that bring the issue back here? They don't appear to be using CTypes, etc.
JelleZijlstra commentedon Apr 11, 2025
That does look like it could be a CPython issue, though ollama has a few dependencies that include compiled code. I tried to reproduce it (3.13.1, MacOS, latest ollama) but I got
httpx.ConnectError: [Errno 61] Connection refused
instead (does ollama require a local server or something? probably not something I'm interested in setting up).Two useful ways forward could be:
Jacoblightning commentedon Apr 11, 2025
Yes. The ollama package requires ollama to be installed and running a local server.
Jacoblightning commentedon Apr 11, 2025
Running python with the debug build I just compiled produces:
JelleZijlstra commentedon Apr 11, 2025
On current 3.13 tip that line in datetime is
cpython/Modules/_datetimemodule.c
Line 2745 in 089c43f
31 remaining items