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版)
238
第
15
章
进程和并发
计算机能做,但大部分人做不到的事就是被封在纸板箱中,放进仓库里。
——
Jack Handey
本章和接下来的两章有些难度。本章介绍时间中的数据(顺序访问和并发访问),第
16
章介
绍存储中的数据(特殊文件和数据库的存储与检索),第
17
章介绍空间中的数据(联网)
。
15.1
程序和进程
当你运行程序时,操作系统会创建相应的
进程
。进程要使用系统资源(
CPU
、内存和磁盘
空间)和操作系统
内核
数据结构(文件和网络连接、用量统计等)。进程之间相互隔离,
无法看到彼此的操作,也干涉不了对方。
操作系统会跟踪所有运行着的进程,给每个进程一点儿运行时间,然后切换到下一个进
程,其目标有两个:公平分摊工作并对用户做出响应。可以使用图形用户界面
[
比如
Mac
的活动监视器(在
macOS
中
)、
Windows
的任务管理器,或者
Linux
的
top
命令
]
查看进
程状态。
也可以在自己的程序中访问进程数据。标准库的
os
模块提供了一种访问某些系统信息的通
用方法。例如,下列函数可以获得正在运行着的
Python
解释器的
进程
ID
和
当前工作目录
:
>>> import os
>>> os.getpid()
76051
>>> os.getcwd()
'/Users/williamlubanovic'
以下代码可以获取我的
用户
ID
和
组
ID
。
进程和并发
|
239
>>> os.getuid()
501
>>> os.getgid()
20
15.1.1
使用
subprocess
创建进程
到目前为止,我们看到的所有程序都是单独的进程。可以使用标准库的 ...
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