You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[mypyc] Enable partial, unsafe support for free-threading (#19167)
Enable multi-phase init when using a free-threaded (no-GIL) CPython
build so we can enable proper multihreading.
Work on mypyc/mypyc#1104. Work on mypyc/mypyc#1038.
The implementation is still quite incomplete. We are missing
synchronization in various places, so race conditions can cause
segfaults. Only single-module compilation units are supported for now.
Here's a toy benchmark I used to check that free threading works and can
improve performance:
```
import sys
import threading
import time
def fib(n: int) -> int:
if n <= 1:
return n
else:
return fib(n - 1) + fib(n - 2)
NTHREADS = 6
print(f"Using {NTHREADS} threads")
print(f"{sys._is_gil_enabled()=}")
t0 = time.time()
threads = []
for i in range(NTHREADS):
t = threading.Thread(target=lambda: fib(36))
t.start()
threads.append(t)
for t in threads:
t.join()
print()
print('elapsed time:', time.time() - t0)
```
0 commit comments