Real Concurrency in Python 3.14: InterpreterPoolExecutor and Beyond

前言 / Introduction 隨著 Python 3.14 的正式發布,多線程開發的限制,也隨著下面的改動迎刃而解: Free-threaded mode (PEP 703), Isolated interpreters (PEP 684), And the new InterpreterPoolExecutor (PEP 734), Python can now run true parallel CPU-bound code directly — even within the same process. 下面將展示一些 Example Async I/O CPU-bound parallelism Multicore execution with interpreter pools 1. Classic Problem: Async + CPU Work 如果你遇到需要 You fetch data from multiple APIs (I/O-bound) Then process, analyze, or compress the data (CPU-bound) 在 Python 3.14 之前 ...

September 29, 2025 · 3 min · 558 words · Daniel Ho

The GIL Problem and What Changes in Python 3.13+

前言 / Introduction 我們在上一篇講述了如何有效的處理 I/O bound 的方法,但實際上困擾 Python 開發的問題在於 CPU bound,原因來自 Global Interpreter Lock (GIL)。 這項限制導致 CPU-bound work slow,迫使許多開發者放棄Python,轉而使用其他語言去進行開發。 但這將會是過去式! 從 Python 3.12,尤其是 3.13 and 3.14,Python 進行大量的改動,使其能夠有效的開發多線程: Multiple interpreters running in parallel (PEP 684, PEP 734) Free-threaded mode (PEP 703) New executors like InterpreterPoolExecutor Less performance penalty compared to past experimental builds 在這篇文章將簡短討論 why the GIL was a bottleneck ,過去的情況是如何,以及有甚麼改變。 What the GIL Really Does The Global Interpreter Lock ensures that only one thread executes Python bytecode at a time — even on a multicore machine. ...

September 29, 2025 · 3 min · 573 words · Daniel Ho

Asyncio vs Threads: Avoiding I/O Blocking in Modern Python

前言 / Introduction 在 Python 專案的開發過程,或多或少會碰到需要平行運行的時候,而大多的資料只說使用 asyncio 就可以加速,但實際上執行時,卻還是一樣的緩慢甚至更糟,那或許你也踩到了錯誤使用線程的坑。 在這篇文章,將討論下面幾點: Why I/O-bound and CPU-bound tasks behave differently The right way to use asyncio Why requests.get() blocks async functions- This sets the foundation for understanding Python 3.13 and 3.14 improvements later in the series. I/O-Bound vs CPU-Bound: The Real Difference 在討論 asyncio or threads 之前,我們需要先搞清楚甚麼樣的任務類型是你面對的 Type What slows it down? Best approach I/O-bound Waiting on network, files, DB, API asyncio, threads CPU-bound Calculations, parsing, encoding multiprocessing, free-threading If your app is fetching APIs, reading files, or handling sockets → it’s I/O-bound. If it’s crunching data or doing math → it’s CPU-bound. 本篇文章為了更清楚描述,接下來會專注在 I/O-bound 的討論。 ...

September 29, 2025 · 2 min · 362 words · Daniel Ho

My First PyCon Talk: From PyTorch to ONNX

前言 / Introduction This year, I did something a little scary but really exciting: I submitted a talk to PyCon TW! The topic? From PyTorch to ONNX: Building an Efficient Image Classification API with a Real-Time Web Demo. Yeah, it’s a long title — but it pretty much sums up everything I’ve learned since college (Computer Vision). This post is just a chill recap of how I got here, why I wanted to do it, and how AI tools (ChatGPT & Cursor) helped me along the way. ...

May 9, 2025 · 2 min · 419 words · Daniel Ho

Tech Share Uv

前言 / Introduction Why I Switched to uv Instead of Anaconda Recently, I discovered uv — a lightning-fast Python package and environment manager built in Rust. After trying it out in a few projects, I realized: Anaconda is not useful to me anymore. Here’s why I made the switch and how it improved my Python workflow. 最近我發現了uv,一個由Rust編寫的輕量化Python 套件與環境管理器。嘗試在我的幾個小專案使用後,竟發現:Anaconda 不會再是我的首選。 所以這篇文章想和大家聊聊,我為什麼選擇轉換,以及uv帶來哪些實際改善。 The Problem with Anaconda (for Me) Anaconda’s installation is heavy - even Miniconda is too bulky Package installation with pip install is painfully slow Unable to change Python versions in existing virtual environments Virtual environments can’t be easily shared across different workspaces 基於上面幾個痛點,總是讓我對Anaconda恨得牙癢癢的,但又離不開它,直到我遇見了uv。 ...

May 5, 2025 · 2 min · 215 words · Daniel Ho