import threading
import sys
import time
def fib(n):
if n < 2: return 1
return fib(n-1) + fib(n-2)
def test():
print(fib(30))
threads = 7
if len(sys.argv) > 1:
threads = int(sys.argv[1])
for i in range(threads - 1):
threading.Thread(target=test, daemon=True).start()
time.sleep(3)
and after a few runs got a segfault.
My current understanding is that when interpreter is shutting down it calls _PyGILState_Fini at some point which invalidates TLS key to PyThreadState, so PyThreadState_GET yields NULL thread state leading to a crash.
I'm not sure how to fix that, and I think it's kind of low priority now, but I though I'll put an issue about that anyway.
I have changed
x.py
to be the following:and after a few runs got a segfault.
My current understanding is that when interpreter is shutting down it calls
_PyGILState_Fini
at some point which invalidates TLS key to PyThreadState, soPyThreadState_GET
yieldsNULL
thread state leading to a crash.I'm not sure how to fix that, and I think it's kind of low priority now, but I though I'll put an issue about that anyway.