返回

Snowflake支持无GIL的Python 3.14t运行时(公开预览)

Snowflake Engineering (Medium) 原文 · 未翻译 发布 2026-12-03 02:54
直接阅读原文
DataHot 速览

Snowflake宣布在公开预览中为Python UDF、UDTF、UDAF和存储过程提供Python 3.14t无GIL运行时。新执行模型让多个worker以线程形式共享同一Python进程,实现包只导入一次、模型与查找表共享内存、CPU密集型任务真正多核并行。用户只需在函数级设置runtime_version='3.14t'即可启用,适合使用线程做并行计算、加载大模型或内存受限的场景。

原收录理由(待核验):这是数据平台在计算运行时层面的实质性工程更新,直接改变Python UDF与存储过程的并行执行模型和内存开销,对在数仓内做特征工程、模型推理的数据团队有直接参考价值。

本文目录 7 节
  1. Why use Python 3.14t
  2. Choose the right runtime for each function
  3. Choose 3.14t when
  4. Choose 3.14 when
  5. Before you switch to 3.14t
  6. Current limitations in Public Preview
  7. Getting started

原文

Python 3.14 ships a free-threaded runtime, 3.14t, without the Global Interpreter Lock. Snowflake now offers it as a runtime for Python UDFs, UDTFs, UDAFs, and stored procedures. Your Python code runs in parallel across available cores, with faster startups and lower memory overhead, and you can opt in at the function level. Opting in is one line: set runtime_version = '3.14t'.

CREATE OR REPLACE FUNCTION my_udf(x NUMBER)
  RETURNS NUMBER
  LANGUAGE PYTHON
  RUNTIME_VERSION = '3.14t'
  HANDLER = 'run'
AS $$
def run(x):
    return x * 2
$$;

Why use Python 3.14t

The standard Python runtimes in Snowpark run each parallel function instance in its own process, which gives every instance a fully isolated environment. On 3.14t, Snowpark runs your Python workers as threads inside one shared Python process. Packages are imported once, data you load once is shared, and threads run in parallel across available cores.

The free-threaded interpreter itself isn’t what makes things faster. The benefits come from this new Snowpark execution model, which free threading makes possible.

  • Faster startup: With one shared process, Snowpark starts your code faster and imports packages once rather than once per instance.
  • A smaller memory footprint: Libraries, models, and lookup tables are loaded once and shared across threads. That leaves more headroom for your data and can reduce out-of-memory errors on memory-heavy workloads.
  • Real parallelism: Threads you start in your handler now run in parallel. A stored procedure can spread CPU-bound work, such as feature engineering, scoring, or parsing, across cores with standard concurrent.futures code.
from concurrent.futures import ThreadPoolExecutor

def run(session, items):
    with ThreadPoolExecutor() as pool:
        return list(pool.map(score, items))

Choose the right runtime for each function

Snowpark offers both Python 3.14 and 3.14t runtimes.

Choose 3.14t when

  • Your stored procedures use threads for CPU-bound parallel work
  • Your UDFs load large models, embeddings, or reference data and only read them
  • Your queries call many Python functions, or your functions import heavy libraries
  • Memory is the limiting factor for your Python workload

Choose 3.14 when

  • You want existing functions to keep their current behavior without any changes
  • Your code is not necessarily thread-safe. See the community porting guide for common thread-safety pitfalls
  • A dependency with native code doesn’t support free threading yet, or you use Anaconda packages
  • You use joblib multiprocessing, Python profiling, or emit telemetry from threads you create

Before you switch to 3.14t

  • Check your packages. 3.14t supports packages only through Artifact Repository, from PyPI or a customer-hosted repository; Anaconda packages aren’t available. Every package with a native extension must declare free-threading support, and many don’t yet. The community-maintained tracker shows the status of popular libraries.
  • Keep shared state limited. Workers and functions in the same query share one Python process, so module-level state, including settings like np.random.seed() and pd.set_option(), is shared too. Keep mutable state local to each call, or protect it with threading.Lock.
  • Use threads for parallelism. joblib’s Loky and multiprocessing backends aren’t supported. Use concurrent.futures.ThreadPoolExecutor instead; on 3.14t, threads run in parallel.
  • Compare before you switch. Run the same function on 3.14 and 3.14t and check results, latency, and memory.

Current limitations in Public Preview

  • Python profiling isn’t supported yet.
  • Telemetry (logs and traces) can’t be emitted from threads you create in your handler. Emit it from the handler’s main thread.
  • joblib’s Loky and multiprocessing backends aren’t supported. Use native threading for parallel processing.
  • Snowflake ML (snowflake-ml-python), including Model Registry, isn’t supported on 3.14t yet.

Getting started

Refer to the Snowflake documentation to learn more. Pick a memory-heavy UDF or a CPU-bound stored procedure, switch the runtime_version to 3.14t, and see the difference for yourself.

Python Without the GIL: Snowflake Supports Free-Threaded Python 3.14t (Public Preview) was originally published in Snowflake Builders Blog: Data Engineers, App Developers, AI, & Data Science on Medium, where people are continuing the conversation by highlighting and responding to this story.

阅读记录仅保存在当前浏览器,用于「为你」推荐。管理阅读记录

这篇内容对你有用吗?

反馈只用于改善内容筛选,不等同于收藏

分享这条资讯
分享海报
保存图片
iOS 也可以长按图片保存