平行化就一定比較快嗎?答案可能跟你想像的不一樣。在 Python 中有一個惡名昭彰的 GIL (Global Interperter Lock),若你沒有了解過它,那麼你的平行化程式很可能無法發揮預期的效能。
在這場議程中,你會了解何謂 GIL,以及如何善用這個大家所認為的缺點,並且了解到如何克服 GIL 所帶來的效能瓶頸。
先備知識
- 寫過 Python
- 知道 Thread 與 Process 有何差異
- 對作業系統有基礎認識
SITCON 2020 共筆
SITCON 2020
2020
共筆
R2
歡迎大家來到SITCON 2020 ヽ(✿゚▽゚)ノ
共筆入口:https://hackmd.io/@SITCON/2020
手機版請點選上方 按鈕展開議程列表。
請從這裡開始
mutex: 互斥體(by Google 翻譯)
CPython 的實作才會有 GIL,保護 Python Object 不會被多個 Thread 同時操作
確保只有一個執行緒執行一條 byteCode
time.sleep 裡面有包含一個 begin allow thread.
GIL 設計是為了 CPython 的撰寫,不是為了 Python 使用者
Python 自己寫多執行緒時,還是需要 Lock(但有些是 thread safe)
對 Python 來說每一條 bytecode 是 atomic
Use multiprocessing replace threading
或使用 asyncio, affinity 模組
或者換成 Jython, IronPython 直譯器
IO bound 程式還是可以用 threading(因為 io 本來就會釋放)
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing