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 技術手冊 第三版
579
18
非同步的替代方案
對於
I/O bound
的程式碼(代表花很多時間進行輸入 / 輸出的程式碼),效
能最佳的架構通常是
非同步
asynchronous
,即
async
)的,只要 I/O 作業
可以是
非阻斷
nonblocking
的,這代表你的程式碼可以發起一個作業,
並在那個作業進行的同時,去做其他的事情,然後找出該作業何時完成。
Async 架構有時也稱為
事件驅動
event-driven
架構,因為 I/O 作業的完
成(輸入管道上有新的資料可取用,或輸出管道準備好接受新的資料)可
被模型化(modeled)為你程式碼外部的「事件(events)」,而你的程式碼
會以適當的方式回應它們。
非同步的架構(asynchronous architectures)可分為三大類:
在有時被稱為
多工
multiplexed
async 架構的這種架構中,你的程式
碼會追蹤記錄其上可能有作業待處理的 I/O 管道(I/O channels),在一
或多個待處理的 I/O 作業完成前你什麼都沒辦法做的情況中,執行你程
式碼的執行緒會進入阻斷中的等候(blocking wait,這種情形通常被稱
為「你的程式碼
阻斷
blocks
了」),明確地說,是在相關的一組管
道上等候任何的完成。當某個完成喚醒了阻斷中的等候,你的程式碼
就會處理那個完成的具體細節(這種處理可能包括發動更多的 I/O
業),然後,通常就會回到阻斷中的等候。Python 提供了數個低階模
組,支援多工的非同步架構,但要用的話,最好還是高階的 ...
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