Thursday, December 12, 2024

Free-threaded python support is coming to PyScripter

One of the main limitations of Python has been its inability to make use of the multiple cores of modern CPUs, at least not easily. This is due to the infamous Global Interpreter Lock.  In essence, due to the presence of the GIL, only one python thread can execute at a time,

Python 3.13 has changed this and provides an experimental free-threaded (or No-GIL) version.  It is included in the standard installer, but you need to select the relevant option (see below) to install it.

Python 3.13 Windows Installer

What you get is a another python executable called python3.13t.exe alongside python.exe.   This executable runs the free-threaded version of python.

This RealPython article provides an in-depth coverage of free-threaded python and is recommended reading. .

The next version of PyScripter will include support for free-treaded Python. The Run, Python Engine submenu now includes an option to use the Free-Threaded version if is available.  It also allows you to easily switch between the standard and free-threaded version.


To get an idea of the performance benefits from using free-threaded python, here are the the results of running the benchmark code of the RealPython article without/with free-threading:

*** Python 3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32. ***
>>> =======================================================================
💻 Windows 64bit with 20x CPU cores (Intel64 Family 6 Model 151 Stepping 2, GenuineIntel Little Endian)
🐍 CPython 3.13.0 C:\Python\Python313\python.exe
Free Threading: unsupported
=======================================================================
Running 20 threads...: 15.07s


*** Python 3.13.0 experimental free-threading build (tags/v3.13.0*** Remote Interpreter Reinitialized ***
=======================================================================
💻 Windows 64bit with 20x CPU cores (Intel64 Family 6 Model 151 Stepping 2, GenuineIntel Little Endian)
🐍 CPython 3.13.0 C:\Python\Python313\python3.13t.exe
Free Threading: enabled ✨
========================================================================
Running 20 threads...: 2.81s



No comments: