Python 3.13 Is Here
Written by Mike James   
Wednesday, 09 October 2024

As time ticks on, the changes to the Python language become fewer and this makes it easier to upgrade. With this release the emphasis is on performance rather than new features.

You can almost certainly just upgrade to the new version and unless you were doing something very advanced you are unlikely to hit any snags. Of course, if you were doing something that advanced and subtle, then you will have no trouble fixing it. For example, the behavior of locals has changed, but if you are introspecting code to that extent then you know what you are doing. Also note that Python 3.8 is almost at end of life.

pfsbanner

As one who rarely uses the Python interactive shell, the fact that there is a new one hardly effects me, but it is prettier I have to agree and if you don't like it the previous one is still available. If you really want to work interactively with Python then use Jupiter.

Of course, the big change and the one we have all been following is threading with the GIL disabled. This is still experimental and you need to turn it on with an environment variable or command line option. Just in case you missed the fuss about the GIL, it locks the Python interpreter so that only a single thread can be executing it at any given time. What this means is that you cannot implement parallel processing in Python using threads.

To be clear, it is still worth using threads in Python 3.13 if you need to wait on something to complete - then some threads can get on with their tasks while other threads are suspended. Threading can increase the speed of a program, but only if the single-threaded version is held up waiting for something. In GIL-bound Python adding threads doesn't speed up a CPU-bound program. If you want to speed a CPU-bound program up then you have to use multiple processes, each with their own copy of the Python interpreter.

What getting rid of the GIL does is to allow CPU-bound programs to run faster with a single copy of the Python interpreter using multiple cores. Many have said that not many applications are going to benefit from GIL-free threading, but clearly there are some important ones that will - AI programs, for example. Such programs could have used process-based parallelism to gain speedups, but processes don't share memory and hence don't share variables. This makes locking unnecessary, but it also makes communication between tasks much more difficult. 

The bottom line is that with the GIL turned off you can write multi-threaded Python programs just as you do in almost any other language. There is also the possiblity that there might be some very weird bugs in there somewhere and it will take time to discover if there are.

It's not all good, however. Python extensions don't automatically support no-GIL mode and you need to find out if your program needs any that currently don't.

Probably more important to the average Python programmer is the introduction of a JIT compiler. This too is experimental and you have to enable it to find out if it makes your program run any faster. So far. the speed gains are described as "modest" and we will have to see if things get faster and the compiler is improved. More importantly, this marks a change in how Python executes code and it will be interesting to see how this develops in the future.

python3

  • Mike James is the author of the Programmer's Python: Something Completely Different series of books which set out to show how Python diverges from other programming languages and how its special features deserve our attention. Programmer’s Python: Async, on asynchronous and concurrent Python explores the problems posed by the GIL in detail.

More Information

What’s New In Python 3.13

Related Articles

Python 3.12 Is Out And It Has Sub-Interpreters

Goodbye GIL - But Will It Make Python Faster?

Python 3.11 Goes Faster

Python 3.11 Released

Guido And Microsoft Want To Make Python x2 Faster

Microsoft Now Visionary Sponsor Of Python

What Makes Python Great & Greater

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


DuckDB And Hydra Partner To Get DuckDB Into PostgreSQL
11/11/2024

The offspring of that partnership is pg_duckdb, an extension that embeds the DuckDB engine into the PostgreSQL database, allowing it to handle analytical workloads.



Flutter Forked As Flock
05/11/2024

One of developers who worked on the Flutter team at Google has created an open-source form of the framework. Matt Carroll says Flock will be "Flutter+", will remain constantly up to date with Flutter, [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

<ASIN:B0CK3X93KF>

<ASIN:1871962765>

<ASIN:1871962749>

Last Updated ( Wednesday, 09 October 2024 )