The interpreters
module described in PEP554, which is not implemented now. This is backported from the future.
$ pip install backports.interpreters
from backports import interpreters
import threading
def task():
intp = interpreters.create()
intp.run("""
a = 0
for i in range(99999999):
a += i
print(a)
""")
ts = []
for _ in range(8):
t = threading.Thread(target=task)
t.start()
ts.append(t)
for t in ts:
t.join()
Run this code with Python3.12, you will see Python will use 8 cores of CPU:
Only support python3.8+.
「すべてはシュタインズ・ゲートの選択である」