併發模塊(一):thread、threading和select

一 綜述:

*thread模塊缺點較多,建議直接使用threading模塊。

*Due to the Global Interpreter Lock(GIL), in CPython only one thread can execute Python code at once. If you want your application to make better of use of the computational resources of multi-core machines, you are advised to usemultiprocessing. However, threading is still an appropriate model if you want to runmultiple I/O-bound tasks simultaneously.


二 thread模塊:暫不介紹。


三 threading模塊:

(1)屬性。


(2)注意:

*當子線程不是守護線程時,主線程執行完後會等待子線程結束;否則主線程將退出(子線程好像也終止了),與pthread庫不太一樣。


四 select模塊



發佈了473 篇原創文章 · 獲贊 17 · 訪問量 42萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章