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

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate 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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

利用 Python 进行数据分析(原书第2版)

利用 Python 进行数据分析(原书第2版)

Wes McKinney

Publisher Resources

ISBN: 9789864766819