---
title: "An Introduction to the GIL for Python Beginners: Disabling It in Python 3.13 and Leveraging Concurrency - Yu Saito"
tags: PyConTW2025, 2025-organize, 2025-共筆
---
# An Introduction to the GIL for Python Beginners: Disabling It in Python 3.13 and Leveraging Concurrency - Yu Saito
{%hackmd L_RLmFdeSD--CldirtUhCw %}
<iframe src=https://app.sli.do/event/iMPyU67YtVzCkwvD2wxtye height=450 width=100%></iframe>
:::success
本演講提供 AI 翻譯字幕及摘要,請點選這裡前往 >> [PyCon Taiwan AI Notebook](https://pycontw.connyaku.app/?room=HTVMyWibomme3MrkhD7a)
AI translation subtitles and summaries are available for this talk. Click here to access >> [PyCon Taiwan AI Notebook](https://pycontw.connyaku.app/?room=HTVMyWibomme3MrkhD7a)
:::
> Collaborative writing start from below
> 從這裡開始共筆
## Main Idea
- GIL allows only one thread at a time
- PEP 703: Making the GIL Optional
## Comparison with exists methods
- Multithreading: almost the same speed as single loop for calculating Fibonacci number
- Multiprocessing: slightly faster but higher RAM usage
- Asyncio: not suitable for CPU bounded tasks, suitable for I\O bounded operations
- Third-party Libs: Cython, Numpy, ...
## Enabled GIL vs. Disabled GIL
- True parallelism
- Speed improvements vary depending on the program, in Python 3.13, it does not guarantee improved performance.
### Considerations and Precautions
- Code assumed GIL provided safety
- Extension modules e.g. Cython, Numpy, pandas, Pytorch... : check version for disabled GIL support
- Potential Race Conditions: Access & modify shared data across multiple threads
### Comparison with Existing Solutions
||No Easy Data Sharing|Easy Data Sharing|
|:--:|:--:|:--:|
|**True Parallelism**|Multiprocessing|==Disabling GIL==|
|**Not True Parallelism**|x|Multithreading|
## Conclusion
- Consider race condition
- Suitable for CPU bounded tasks
- Consider extension modules' support
## QA
- Practical difficulties: ==Enabling FIL make implementing easier without the need to consider racing conditions.==
- "Easy" data sharing: ==The ability of accessing memory from different processes.==
- Do we need to be more cautious like using `threading.Lock` when coding with disabled GIL? ==Skipped==
- How does disabling the GIL perform compared to other methods, like asyncio or 3rd-party libraries ==Skipped==
Below is the part that speaker updated the talk/tutorial after speech
講者於演講後有更新或勘誤投影片的部份