Skip to Content
Python数据处理
book

Python数据处理

by Jacqueline Kazil, Katharine Jarmul
July 2017
Intermediate to advanced
398 pages
11h 54m
Chinese
Posts & Telecom Press
Content preview from Python数据处理
312
14
通过传递关键参数创建一个进程对象:目标(即,我应该执行哪个函数)和参数(即,使
用什么参数)。这行代码追加所有的进程到一个列表,这样我们可以在一个地方管理它们。
初始化
Manager
对象,这帮助我们管理共享的对象和进程间的日志。
创建一个共享列表对象,跟踪每个站点的状态。每一个进程都能改变这个列表。
创建一个共享的锁对象,如果一个站点中不存在“
is up
”,停止并且宣布它。如果这些
是我们管理的所有站点,我们可能有了一块重要的业务逻辑来处理紧急情况,也因此有
了“停止所有程序”的理由。
分别开始由函数
get_proc
返回的每一个进程。一旦它们开始执行,
join
方法会让
Manager
对象和所有的子进程通信,直到最后一个进程完成。
使用多重处理的时候,你通常会有一个管理者进程和一堆子进程。你可以传递参数给子进
程,可以使用共享内存和共享变量。这使你能够确定如何利用和架构
multiprocessing
。根
据脚本的需要,你或许想要让管理器运行脚本中一系列的逻辑,同时使用子进程运行高延
迟或长时间运行的部分代码。
共享锁对象(
https://docs.python.org/2/library/threading.html#lock-objects
提供了同步执行多个进程的能力,同时能保护内部逻辑的特定区域。有效
使用它们的一个方式是直接放置锁逻辑到
with
https://docs.python.org/2/
library/threading.html#using-locks-conditions-and-semaphores-in-the-with- ...
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

数据科学中的实用统计学(第2版)

数据科学中的实用统计学(第2版)

Peter Bruce, Andrew Bruce, Peter Gedeck
Java持续交付

Java持续交付

Daniel Bryant, Abraham Marín-Pérez
解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787115459190