Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced content levelIntermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
443
14
執行緒和行程
一個
執行緒
thread
是會與其他執行緒共用全域狀態(記憶體)的一
種控制流程(a flow of control);所有的執行緒看起來都像同時執行,但
在單處理器或單核心的機器上,它們通常是「輪流(taking turns)」執行
的。執行緒不容易精通,而多執行緒程式(multithreaded programs)通常
很難測試與除錯;然而,如後面「使執行緒、多行程,或非同步程式設
計?」中所涵蓋的,適當使用時,多執行緒與傳統的「單執行緒(single-
threaded)」程式設計比較起來,效能有時候會比較好。本章涵蓋 Python
提供用來處理執行緒的機能,包括模組
threading
queue
concurrent
一個
行程
process
是執行中的程式的一個實體。作業系統保護行程不
受彼此干擾,想要相互通訊的行程必須藉由
行程間通訊
inter-process
communication
IPC)的機制明確地進行安排。行程可以透過檔案(涵蓋
於第 10 章)與資料庫(涵蓋於第 11 章)來溝通。行程使用資料儲存機制
(例如檔案或資料庫)進行通訊的一般方式是,一個行程寫入資料,而另
一個行程之後讀回那個資料。本章涵蓋 Python 標準程式庫模組
subprocess
multiprocessing
;模組
os
與行程有關的部分,包括使用
管線
pipes
的簡單 IPC;以及稱為
記憶體映射檔案
memory-mapped files
的跨平台
IPC 機制,它透過模組
mmap ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

測試驅動開發|使用 Python

測試驅動開發|使用 Python

Harry J.W. Percival
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9789864766819