자유 스레딩 파이썬

Free-threaded Python

GIL을 끄는 빌드에서 파이썬 스레드가 CPU 작업을 병렬 실행할 수 있습니다.

···
html
<div class="v"><header><b>PYTHON THREADS</b><span id="state"></span></header><main><div class="mode" id="mode"></div><div class="timeline" id="timeline"></div></main><footer>illustrative CPU schedules</footer></div>
css
.v{width:min(92vw,660px);height:min(86vh,310px);box-sizing:border-box;padding:clamp(9px,2.5vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);display:flex;flex-direction:column;gap:7px;color:var(--fg);font:500 clamp(15px,3.2vmin,17px)/1.25 var(--font-sans, sans-serif)}.v header,.v footer{display:flex;justify-content:space-between;align-items:center;gap:8px;white-space:nowrap}.v header b{color:var(--accent);font-size:.9em}.v header span,.v footer{color:var(--muted);font-size:.82em}.v main{flex:1;min-height:0;position:relative;overflow:hidden}.v .mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.v .active{background:var(--accent)!important;color:var(--bg)!important;border-color:var(--accent)!important}.v .muted{opacity:.28} .mode{text-align:center;height:23%;color:var(--accent);font:600 .85em ui-monospace,monospace}.timeline{height:70%;display:flex;flex-direction:column;justify-content:center;gap:7px}.lane{height:30px;border:1px solid var(--line);border-radius:5px;position:relative;font:600 .8em ui-monospace,monospace;padding-left:4px;line-height:30px}.bar{position:absolute;top:3px;height:22px;background:var(--accent);border-radius:4px;transition:left .35s,width .35s;opacity:.8}
js
let n=0;function draw(){document.getElementById("mode").textContent=n?"GIL disabled: overlap":"GIL enabled: turns";document.getElementById("timeline").innerHTML=[0,1].map(i=>"<div class=lane>T"+(i+1)+"<div class=bar style=\"left:"+(n?18:i?51:18)+"%;width:"+(n?65:42)+"%\"></div></div>").join("");document.getElementById("state").textContent=n?"parallel":"alternating";n=1-n}draw();setInterval(draw,1400)

Python 3.14에서 자유 스레딩 빌드는 공식 지원 상태입니다. GIL을 비활성화하면 두 스레드가 파이썬 코드를 여러 코어에서 동시에 실행할 수 있습니다.

기본 빌드가 모두 자동으로 자유 스레딩이 되는 것은 아닙니다. 확장 모듈의 호환성과 공유 가변 상태의 동기화도 확인해야 합니다. 데모는 같은 두 CPU 작업의 실행 구간이 겹치는 차이를 개념적으로 보여줍니다.

언제 쓰나

파이썬 스레드로 CPU 작업을 병렬화할 때 빌드와 의존성 호환성을 평가합니다.

페이지로 열기 ↗