Free-threaded Python

자유 스레딩 파이썬

A build with the GIL disabled lets Python threads run CPU work in parallel.

···
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 officially supports a free-threaded build. With the GIL disabled, threads can execute Python code on multiple cores at once.

This is not automatically the mode of every default build. Extension compatibility and synchronization of mutable shared state still matter. The demo conceptually compares overlap between two CPU jobs.

When to use

Evaluate the build and dependencies when parallelizing CPU work with Python threads.

Open as page ↗