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 技術手冊 第三版
selectors 模組
|
607
selectors 模組
selectors
只存在於 v3 中的 Python 標準程式庫。然而,你可以藉由
pip2
install selectors34
安裝 v2 的後向移植版,然後,為了可移植性,以這種
方式編寫你的 import
try:
import selectors
except ImportError:
import selectors34 as selectors
selectors
支援 I/O 的多工(multiplexing),從較低階的模組
select
挑選最
適合你平台的機制,你不需要知道
select
的低階細節,因此本書沒有涵蓋
select
selectors
能夠處理的檔案種類取決於你的平台。Sockets(涵蓋於第 17
章)在所有的平台上都有支援,在 Windows 上,則不支援其他種類的檔
案。在類 Unix 系統上,可能有支援其他種的檔案(要以非阻斷模式開啟一
個檔案,就使用低階呼叫
os.open
,並用旗標
os.O_NONBLOCK
)。
selectors 的事件
selectors
提供兩個常數:
EVENT_READ
(代表檔案可供讀取)和
EVENT_WRITE
(代表檔案可供寫入)。要同時表示這兩個事件,就用「位元 OR」運算子
|
,如同:
selectors.EVENT_READ | selectors.EVENT_WRITE
SelectorKey 類別
選擇器類別(selector classes)的方法回傳類別
SelectorKey ...
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