Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
Python语言及其应用(第2版)
by
Bill Lubanovic
March 2022
Intermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from
Python语言及其应用(第2版)
244
|
第
15
章
•
sh
•
delegator
•
pypeln
15.3
并发
官方
Python
网站基于标准库对并发做了一般性讨论,给出了各种包和技术的链接,本章将
展示其中最实用的部分。
在计算机中,如果你的程序在等待,那么通常是出于以下某个原因。
I/O
受限
这是最常见的原因。计算机
CPU
运行速度极快
,是内存的数百倍,是磁盘或网络的数
千倍。
CPU
受限
CPU
持续繁忙。这发生在
数字运算
任务中,比如科学计算或图形计算。
下面是两个与并发相关的术语。
同步
一件事跟着另一件事,就像一排小鹅跟在它们的父母后面一样。
异步
任务是独立的,就像小鹅随机跳入池塘中。
当你从简单的系统和任务转向现实问题时,迟早得处理并发。考虑一个网站。你通常必须
为
We
b
客户快速地返回静态网页和动态网页。几分之一秒的时间还可以被认为是具有互动
性,但如果时间再长一点儿,人们就会变得不耐烦。谷歌和亚马逊等公司的测试表明,如
果页面的加载速度哪怕慢了一点儿,流量就会迅速下滑。
但如果你对那些耗时的任务(比如上传文件、调整图片大小或查询数据库)又无能为力,
该怎么办呢?在并发的
We
b
服务器代码中是无法解决的,因为同步必然会产生等待。
在单台计算机中,要想尽可能快地执行多个任务,就得让任务之间独立。缓慢的任务不应
该阻塞其他任务。
本章前面展示过
multiprocessing
如何用于单机并发任务。如果需要调整图片大小,则
Web
服务器代码应该调用一个独立的
、专门的图片缩放进程,以异步方式并发运行。它通
过调用多个缩放过程来水平扩展应用。
诀窍在于让它们彼此协同工作。任何共享的控制或状态都将意味着瓶颈。一个更大的诀窍 ...
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编程入门与实战
Posts & Telecom Press, Fabrizio Romano
Python实用技能学习指南
Posts & Telecom Press, Robert Smallshire, Austin Bingham
Python技术基础视频教程
保罗·J·戴特尔
Python面向对象编程指南
Posts & Telecom Press, Steven F. Lott
Publisher Resources
ISBN: 9787115586223