larryhastings / gilectomy

Gilectomy branch of CPython. Use "gilectomy" branch in git. Read the important, short README below!
Other
527 stars 43 forks source link

Daemon threads seem to be broken #35

Open JustAMan opened 8 years ago

JustAMan commented 8 years ago

I have changed x.py to be the following:

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.