Tech

Python 3.15 beta freezes features, adding structured concurrency and thread safety tools

The Python 3.15.0b1 feature freeze reveals overlooked updates in structured concurrency, threading utilities, and immutable data types, complementing major announcements like lazy imports.

Author
Owen Mercer
Markets and Finance Editor
Published
Draft
Source: Hacker News · original
Tech
No image available
New release brings graceful TaskGroup cancellation, async context managers, and frozendict support

Python 3.15.0b1 has reached its feature freeze, setting the stage for a final release later this year. While major announcements such as lazy imports and the tachyon profiler have dominated discussions, the beta release introduces several significant updates for developers working with structured concurrency, threading, and data immutability.

A key addition for structured concurrency is the new TaskGroup.cancel method. This function allows for the graceful cancellation of a task group without raising exceptions, simplifying the process of interrupting concurrent tasks. Previously, developers had to manage ExceptionGroup objects and use contextlib.suppress to handle interruptions, a process that was often cumbersome. The new method streamlines this workflow by cleanly terminating the group.

ContextDecorator support has also been enhanced to correctly handle async functions, async iterators, and standard iterators. In earlier versions, using a context manager as a decorator on an async function caused the decorator to complete immediately upon function call, rather than wrapping the entire lifecycle. Python 3.15 ensures the decorator covers the full lifespan of the wrapped function, addressing a long-standing semantic issue.

Threading utilities have been expanded to improve thread safety without requiring developers to change their abstractions. The new threading.serialize_iterator function wraps iterators to ensure serialised access, preventing skipped values or broken internal state in multi-threaded environments. Additionally, threading.synchronized_iterator provides a decorator for generator functions, while threading.concurrent_tee duplicates values across multiple iterators, offering an alternative to using Queues for synchronising consumption.

Other notable changes include support for set operations, such as XOR, on collections.Counter objects, adding completeness to the class. The release also introduces frozendict, an immutable and hashable type for representing JSON objects. Corresponding updates to json.load and json.loads now accept an array_hook parameter, complementing the existing object_hook to parse JSON arrays directly into frozendict or other immutable forms.

Continue reading

More from Tech

Read next: Apple opens developer access to iOS, iPadOS and macOS 27 betas
Read next: Apple confirms macOS 27 Golden Gate requires Apple Silicon, ending Intel support
Read next: Apple unveils watchOS 27 with Siri AI integration and hardware restrictions