# Thread & Process ## Week 2A ---- ## 說文解字 Thread 執行緒 Process 行程 每個 Process 底下 可以同時有多個 Threads ---- ## Thread or Process? 兩者都是用來做平行處理的 但特性上有很大的不同 ---- ## Memory Thread 共享記憶體比較簡單 適合 IO 密集的任務,例如下載檔案 Process 共享記憶體比較複雜 適合 CPU 密集的任務,例如多個實驗 ---- ## Python GIL Global Interpreter Lock (GIL) GIL 限制**任何時刻**只有一個 Thread 可以執行 Python Bytecode 在 CPU 密集的任務中會顯著變慢 可以透過 Process 突破限制 ---- ## concurrent 套件 Python 內建的 [`concurrent`](https://docs.python.org/3/library/concurrent.futures.html) 套件 提供高階介面簡單操作多執行緒 / 多行程 ---- ## CUDA 若是跟 PyTorch CUDA 相關的多行程操作 則需要跟 `torch.multiprocessing` 搭配
{"title":"Week 2A - Thread & Process","slideOptions":"{\"transition\":\"slide\"}","description":"地獄貓旅行團第 42 週心得分享","contributors":"[{\"id\":\"c7cbb212-2c41-4dfa-8d85-f8e7fa769bf1\",\"add\":671,\"del\":79}]"}
    307 views
   Owned this note