ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.3 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://developer.aliyun.com/article/1598648 |
| Last Crawled | 2026-03-28 12:09:03 (9 days ago) |
| First Indexed | 2024-09-01 09:08:11 (1 year ago) |
| HTTP Status Code | 200 |
| Meta Title | Python multiprocessing模块 -阿里云开发者社区 |
| Meta Description | Python multiprocessing模块 |
| Meta Canonical | null |
| Boilerpipe Text | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
参考博客:http:
//www.cnblogs.com/Anker/p/3271773.html
一:僵尸进程(有害)
僵尸进程:一个进程使用fork创建子进程,如果子进程退出,而父进程并没有调用wait或waitpid获取子进程的状态信息,那么子进程的进程描述符仍然保存在系统中。这种进程称之为僵死进程。详解如下
我们知道在unix/linux中,正常情况下子进程是通过父进程创建的,子进程在创建新的进程。子进程的结束和父进程的运行是一个异步过程,即父进程永远无法预测子进程到底什么时候结束,如果子进程一结束就立刻回收其全部资源,那么在父进程内将无法获取子进程的状态信息。
因此,UNⅨ提供了一种机制可以保证父进程可以在任意时刻获取子进程结束时的状态信息:
1、在每个进程退出的时候,内核释放该进程所有的资源,包括打开的文件,占用的内存等。但是仍然为其保留一定的信息(包括进程号the process ID,退出状态the termination status of the process,运行时间the amount of CPU time taken
by
the process等)
2、直到父进程通过wait / waitpid来取时才释放. 但这样就导致了问题,如果进程不调用wait / waitpid的话,那么保留的那段信息就不会释放,其进程号就会一直被占用,但是系统所能使用的进程号是有限的,如果大量的产生僵死进程,将因为没有可用的进程号而导致系统不能产生新的进程. 此即为僵尸进程的危害,应当避免。
任何一个子进程(init除外)在exit()之后,并非马上就消失掉,而是留下一个称为僵尸进程(Zombie)的数据结构,等待父进程处理。这是每个子进程在结束时都要经过的阶段。如果子进程在exit()之后,父进程没有来得及处理,这时用ps命令就能看到子进程的状态是“Z”。如果父进程能及时 处理,可能用ps命令就来不及看到子进程的僵尸状态,但这并不等于子进程不经过僵尸状态。 如果父进程在子进程结束之前退出,则子进程将由init接管。init将会以父进程的身份对僵尸状态的子进程进行处理。
二:孤儿进程(无害)
孤儿进程:一个父进程退出,而它的一个或多个子进程还在运行,那么那些子进程将成为孤儿进程。孤儿进程将被init进程(进程号为1)所收养,并由init进程对它们完成状态收集工作。
孤儿进程是没有父进程的进程,孤儿进程这个重任就落到了init进程身上,init进程就好像是一个民政局,专门负责处理孤儿进程的善后工作。每当出现一个孤儿进程的时候,内核就把孤 儿进程的父进程设置为init,而init进程会循环地wait()它的已经退出的子进程。这样,当一个孤儿进程凄凉地结束了其生命周期的时候,init进程就会代表党和政府出面处理它的一切善后工作。因此孤儿进程并不会有什么危害。
我们来测试一下(创建完子进程后,主进程所在的这个脚本就退出了,当父进程先于子进程结束时,子进程会被init收养,成为孤儿进程,而非僵尸进程),文件内容
import os
import sys
import time
pid = os.getpid()
ppid = os.getppid()
print
'im father'
,
'pid'
, pid,
'ppid'
, ppid
pid = os.fork()
#执行pid=os.fork()则会生成一个子进程
#返回值pid有两种值:
# 如果返回的pid值为0,表示在子进程当中
# 如果返回的pid值>0,表示在父进程当中
if
pid > 0:
print
'father died..'
sys.exit(0)
# 保证主线程退出完毕
time.sleep(1)
print
'im child'
, os.getpid(), os.getppid()
执行文件,输出结果:
im father pid 32515 ppid 32015
father died..
im child 32516 1
看,子进程已经被pid为1的init进程接收了,所以僵尸进程在这种情况下是不存在的,存在只有孤儿进程而已,孤儿进程声明周期结束自然会被init来销毁。
三:僵尸进程危害场景:
例如有个进程,它定期的产 生一个子进程,这个子进程需要做的事情很少,做完它该做的事情之后就退出了,因此这个子进程的生命周期很短,但是,父进程只管生成新的子进程,至于子进程 退出之后的事情,则一概不闻不问,这样,系统运行上一段时间之后,系统中就会存在很多的僵死进程,倘若用ps命令查看的话,就会看到很多状态为Z的进程。 严格地来说,僵死进程并不是问题的根源,罪魁祸首是产生出大量僵死进程的那个父进程。因此,当我们寻求如何消灭系统中大量的僵死进程时,答案就是把产生大 量僵死进程的那个元凶枪毙掉(也就是通过kill发送SIGTERM或者SIGKILL信号啦)。枪毙了元凶进程之后,它产生的僵死进程就变成了孤儿进 程,这些孤儿进程会被init进程接管,init进程会wait()这些孤儿进程,释放它们占用的系统进程表中的资源,这样,这些已经僵死的孤儿进程 就能瞑目而去了。
四:测试
#1、产生僵尸进程的程序test.py内容如下
#coding:utf-8
from
multiprocessing import Process
import time,os
def run():
print(
'子'
,os.getpid())
if
__name__ ==
'__main__'
:
p=Process(target=run)
p.start()
print(
'主'
,os.getpid())
time.sleep(1000)
#2、在unix或linux系统上执行
[root@vm172-31-0-19 ~]# python3 test.py &
[1] 18652
[root@vm172-31-0-19 ~]# 主 18652
子 18653
[root@vm172-31-0-19 ~]# ps aux |grep Z
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 18653 0.0 0.0 0 0 pts/0 Z 20:02 0:00 [python3] <defunct> #出现僵尸进程
root 18656 0.0 0.0 112648 952 pts/0 S+ 20:02 0:00 grep --color=auto Z
[root@vm172-31-0-19 ~]# top #执行top命令发现1zombie
top - 20:03:42 up 31 min, 3 users, load average: 0.01, 0.06, 0.12
Tasks: 93 total, 2 running, 90 sleeping, 0 stopped, 1 zombie
%Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1016884 total, 97184 free, 70848 used, 848852 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 782540 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
root 20 0 29788 1256 988 S 0.3 0.1 0:01.50 elfin
#3、
等待父进程正常结束后会调用wait/waitpid去回收僵尸进程
但如果父进程是一个死循环,永远不会结束,那么该僵尸进程就会一直存在,僵尸进程过多,就是有害的
解决方法一:杀死父进程
解决方法二:对开启的子进程应该记得使用
join
,
join
会回收僵尸进程
参考python2源码注释
class
Process(
object
):
def
join
(self, timeout=None):
''
'
Wait until child process terminates
''
'
assert self._parent_pid == os.getpid(),
'can only join a child process'
assert self._popen
is
not None,
'can only join a started process'
res = self._popen.wait(timeout)
if
res
is
not None:
_current_process._children.discard(self)
join
方法中调用了wait,告诉系统释放僵尸进程。discard为从自己的children中剔除
解决方法三:http:
//blog.csdn.net/u010571844/article/details/50419798 |
| Markdown | [大模型](https://www.aliyun.com/product/tongyi)[产品](https://www.aliyun.com/product/list)[解决方案](https://www.aliyun.com/solution/tech-solution/)[权益](https://www.aliyun.com/benefit)[定价](https://www.aliyun.com/price)[云市场](https://market.aliyun.com/)[伙伴](https://partner.aliyun.com/management/v2)[服务](https://www.aliyun.com/service)[了解阿里云](https://www.aliyun.com/about)
查看 “
” 全部搜索结果
[ AI 助理](https://www.aliyun.com/ai-assistant?displayMode=side)
[文档](https://help.aliyun.com/)[备案](https://beian.aliyun.com/)[控制台](https://home.console.aliyun.com/home/dashboard/ProductAndService)
[开发者社区](https://developer.aliyun.com/)
[首页](https://developer.aliyun.com/ "开发者社区")
探索云世界
### 探索云世界
#### 热门
[百炼大模型](https://developer.aliyun.com/modelstudio/)[Modelscope模型即服务](https://developer.aliyun.com/modelscope/)[弹性计算](https://developer.aliyun.com/ecs/)[通义灵码](https://developer.aliyun.com/lingma/)[云原生](https://developer.aliyun.com/cloudnative/)[数据库](https://developer.aliyun.com/database/)[云效DevOps](https://developer.aliyun.com/group/yunxiao/)[龙蜥操作系统](https://developer.aliyun.com/group/aliyun_linux/)
#### [云计算](https://developer.aliyun.com/ecs/)
[弹性计算](https://developer.aliyun.com/ecs/)[无影](https://developer.aliyun.com/group/wuying/)[存储](https://developer.aliyun.com/storage/)[网络](https://developer.aliyun.com/group/networking/)[倚天](https://developer.aliyun.com/yitian/)
#### [大数据](https://developer.aliyun.com/bigdata/)
[大数据计算](https://developer.aliyun.com/group/maxcompute/)[实时数仓Hologres](https://developer.aliyun.com/group/hologres/)[实时计算Flink](https://developer.aliyun.com/group/sc/)[E-MapReduce](https://developer.aliyun.com/group/aliyunemr/)[DataWorks](https://developer.aliyun.com/group/dataworks/)[Elasticsearch](https://developer.aliyun.com/group/es/)[机器学习平台PAI](https://developer.aliyun.com/group/pai/)[智能搜索推荐](https://developer.aliyun.com/group/aios/)[数据可视化DataV](https://developer.aliyun.com/group/datav/)
#### [云原生](https://developer.aliyun.com/cloudnative/)
[容器](https://developer.aliyun.com/group/kubernetes/)[serverless](https://developer.aliyun.com/group/serverless/)[中间件](https://developer.aliyun.com/group/aliware/)[微服务](https://developer.aliyun.com/group/mse/)[可观测](https://developer.aliyun.com/group/arms/)[消息队列](https://developer.aliyun.com/group/rocketmq/)
#### [人工智能](https://developer.aliyun.com/modelscope/)
[机器学习平台PAI](https://developer.aliyun.com/group/pai/)[视觉智能开放平台](https://developer.aliyun.com/group/viapi/)[智能语音交互](https://developer.aliyun.com/group/speech/)[自然语言处理](https://developer.aliyun.com/group/nlp/)[多模态模型](https://developer.aliyun.com/group/multimodel/)[pythonsdk](https://developer.aliyun.com/group/pythonsdk/)[通用模型](https://developer.aliyun.com/group/others/)
#### [数据库](https://developer.aliyun.com/database/)
[关系型数据库](https://developer.aliyun.com/group/polardb/)[NoSQL数据库](https://developer.aliyun.com/group/hbasespark/)[数据仓库](https://developer.aliyun.com/group/analyticdb/)[数据管理工具](https://developer.aliyun.com/database/dm)[PolarDB开源](https://developer.aliyun.com/polardb/)[向量数据库](https://developer.aliyun.com/database/vectordatabase)
#### [开发与运维](https://developer.aliyun.com/group/othertech/)
[云效DevOps](https://developer.aliyun.com/group/yunxiao/)[钉钉宜搭](https://developer.aliyun.com/group/yida/)[镜像站](https://developer.aliyun.com/group/mirror/)
[问产品](https://developer.aliyun.com/ask/hottestQuestionsWithProduct)
[动手实践](https://developer.aliyun.com/adc/)
[官方博客](https://developer.aliyun.com/blog/)
[考认证](https://edu.aliyun.com/)
[TIANCHI大赛](https://tianchi.aliyun.com/)
活动广场
### 活动广场
丰富的线上&线下活动,深入探索云世界
[任务中心做任务,得社区积分和周边](https://developer.aliyun.com/mission)
[训练营资深技术专家手把手带教](https://edu.aliyun.com/trainingcamp/)
[直播技术交流,直击现场](https://developer.aliyun.com/live/)
[乘风者计划让创作激发创新](https://developer.aliyun.com/topic/bloggers)
下载
### 下载
海量开发者使用工具、手册,免费下载
[镜像站极速、全面、稳定、安全的开源镜像](https://developer.aliyun.com/mirror)
[技术资料开发手册、白皮书、案例集等实战精华](https://developer.aliyun.com/ebook/)
探索云世界
热门
[百炼大模型](https://developer.aliyun.com/modelstudio/)[Modelscope模型即服务](https://developer.aliyun.com/modelscope/)[弹性计算](https://developer.aliyun.com/ecs/)[通义灵码](https://developer.aliyun.com/lingma/)[云原生](https://developer.aliyun.com/cloudnative/)[数据库](https://developer.aliyun.com/database/)[云效DevOps](https://developer.aliyun.com/group/yunxiao/)[龙蜥操作系统](https://developer.aliyun.com/group/aliyun_linux/)
[云计算](https://developer.aliyun.com/ecs/)[弹性计算](https://developer.aliyun.com/ecs/)[无影](https://developer.aliyun.com/group/wuying/)[存储](https://developer.aliyun.com/storage/)[网络](https://developer.aliyun.com/group/networking/)[倚天](https://developer.aliyun.com/yitian/)
[云原生](https://developer.aliyun.com/cloudnative/)[容器](https://developer.aliyun.com/group/kubernetes/)[serverless](https://developer.aliyun.com/group/serverless/)[中间件](https://developer.aliyun.com/group/aliware/)[微服务](https://developer.aliyun.com/group/mse/)[可观测](https://developer.aliyun.com/group/arms/)[消息队列](https://developer.aliyun.com/group/rocketmq/)
[数据库](https://developer.aliyun.com/database/)[关系型数据库](https://developer.aliyun.com/group/polardb/)[NoSQL数据库](https://developer.aliyun.com/group/hbasespark/)[数据仓库](https://developer.aliyun.com/group/analyticdb/)[数据管理工具](https://developer.aliyun.com/database/dm)[PolarDB开源](https://developer.aliyun.com/polardb/)[向量数据库](https://developer.aliyun.com/database/vectordatabase)
[大数据](https://developer.aliyun.com/bigdata/)[大数据计算](https://developer.aliyun.com/group/maxcompute/)[实时数仓Hologres](https://developer.aliyun.com/group/hologres/)[实时计算Flink](https://developer.aliyun.com/group/sc/)[E-MapReduce](https://developer.aliyun.com/group/aliyunemr/)[DataWorks](https://developer.aliyun.com/group/dataworks/)[Elasticsearch](https://developer.aliyun.com/group/es/)[机器学习平台PAI](https://developer.aliyun.com/group/pai/)[智能搜索推荐](https://developer.aliyun.com/group/aios/)[数据可视化DataV](https://developer.aliyun.com/group/datav/)
[人工智能](https://developer.aliyun.com/modelscope/)[机器学习平台PAI](https://developer.aliyun.com/group/pai/)[视觉智能开放平台](https://developer.aliyun.com/group/viapi/)[智能语音交互](https://developer.aliyun.com/group/speech/)[自然语言处理](https://developer.aliyun.com/group/nlp/)[多模态模型](https://developer.aliyun.com/group/multimodel/)[pythonsdk](https://developer.aliyun.com/group/pythonsdk/)[通用模型](https://developer.aliyun.com/group/others/)
[开发与运维](https://developer.aliyun.com/group/othertech/)[云效DevOps](https://developer.aliyun.com/group/yunxiao/)[钉钉宜搭](https://developer.aliyun.com/group/yida/)[镜像站](https://developer.aliyun.com/group/mirror/)
[开发者社区](https://developer.aliyun.com/) [开发与运维](https://developer.aliyun.com/group/othertech/) [文章](https://developer.aliyun.com/group/othertech/article/) 正文
# Python multiprocessing模块
2024-08-28 236
版权
版权声明:
本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《 [阿里云开发者社区用户服务协议](https://developer.aliyun.com/article/768092)》和 《[阿里云开发者社区知识产权保护指引](https://developer.aliyun.com/article/768093)》。如果您发现本社区中有涉嫌抄袭的内容,填写 [侵权投诉表单](https://yida.alibaba-inc.com/o/right)进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
**简介:** Python multiprocessing模块
### 一、简介
python多线程有个讨厌的限制,全局解释器锁(global interpreter lock),这个锁的意思是任一时间只能有一个线程使用解释器,跟单cpu跑多个程序一个意思,大家都是轮着用的,这叫“并发”,不是“并行”。手册上的解释是为了保证对象模型的正确性!这个锁造成的困扰是如果有一个计算密集型的线程占着cpu,其他的线程都得等着....,试想你的多个线程中有这么一个线程,得多悲剧,多线程生生被搞成串行;当然这个模块也不是毫无用处,手册上又说了:当用于IO密集型任务时,IO期间线程会释放解释器,这样别的线程就有机会使用解释器了!所以是否使用这个模块需要考虑面对的任务类型
python代码执行由python虚拟机(解释器主循环)来控制。对python虚拟机的访问由GIL控制,GIL保证同一时刻只有一个线程在执行。
**python虚拟机执行过程:**
| | |
|---|---|
| 1234567891011 | `1、设置GIL``2、切换到一个线程去运行``3、运行,直至完成指定的字节码指令,或者线程主动让出控制``4、将该线程设置为睡眠状态``5、解锁GIL``6、重复以上所有步骤,运行下一个线程 ` |
由于GIL的限制,python多线程实际只能运行在单核CPU。如要实现多核CPU并行,只能充分地使用多核CPU的资源(os.cpu\_count()查看,在python中大部分情况需要使用多进程。大部分并行模块中,多进程相当于开启多个python解释器,每个解释器对应一个进程。也有一些并行模块通过修改pyhton的GIL机制突破这个限制。
Python提供了multiprocessing。 multiprocessing模块用来开启子进程,并在子进程中执行我们定制的任务(比如函数),该模块与多线程模块threading的编程接口类似。
仔细说来, multiprocess不是一个模块而是python中一个操作、管理进程的包。之所以叫multi是取自multiple的多功能的意思,在这个包中几乎包含了和进程有关的所有子模块。由于提供的子模块非常多,为了方便大家归类记忆,我将这部分大致分为四个部分:创建进程部分,进程同步部分,进程池部分,进程之间数据共享。
### 二、multiprocessing.Process模块
Process模块是一个创建进程的模块, 借助这个模块, 就可以完成进程的创建。
与threading.Thread类似,它利用multiprocessing.Process对象来创建一个进程。
该进程可以运行在Python程序内部编写的函数。
该Process对象与Thread对象的用法相同,也有start(), run(), join()的方法。
此外multiprocessing包中也有Lock/Event/Semaphore/Condition类 (这些对象可以像多线程那样,通过参数传递给各个进程),用以同步进程,其用法与threading包中的同名类一致。
所以,multiprocessing的很大一部份与threading使用同一套API,只不过换到了多进程的情境。
**但在使用这些共享API的时候,我们要注意以下几点:**
| | |
|---|---|
| 123456789 | `在UNIX平台上,当某个进程终结之后,该进程需要被其父进程调用wait,否则进程成为僵尸进程(Zombie)``所以,有必要对每个Process对象调用``join``()方法 (实际上等同于wait)。对于多线程来说,由于只有一个进程,所以不存在此必要性。``multiprocessing提供了threading包中没有的IPC(比如Pipe和Queue),效率上更高。``应优先考虑Pipe和Queue,避免使用Lock/Event/Semaphore/Condition等同步方式 (因为它们占据的不是用户进程的资源)。``多进程应该避免共享资源。在多线程中,我们可以比较容易地共享资源,比如使用全局变量或者传递参数。``在多进程情况下,由于每个进程有自己独立的内存空间,以上方法并不合适。此时我们可以通过共享内存和Manager的方法来共享资源。``但这样做提高了程序的复杂度,并因为同步的需要而降低了程序的效率。 ` |
**使用格式:**
| | |
|---|---|
| 12345 | `multiprocessing.Process(``group``=None, target=None, name=None, args=(), kwargs={}, *, daemon=None),由该类实例化得到的对象,表示一个子进程中的任务(尚未启动)``强调:``1. 需要使用关键字的方式来指定参数``2. args指定的为传给target函数的位置参数,是一个元组形式,必须有逗号` |
**参数介绍:**
```
group为预留参数。
target为可调用对象(函数对象),为子进程对应的活动;相当于multiprocessing.Process子类化中重写的run()方法。
name为线程的名称,默认(None)为"Process-N"。
args、kwargs为进程活动(target)的非关键字参数、关键字参数。
deamon为bool值,表示是否为守护进程。
```
**方法介绍:**
| | |
|---|---|
| 123456789101112131415 | `run():表示进程运行的方法。可以在子类中重写此方法。标准run() 方法调用传递给对象构造函数的可调用对象作为目标参数(如果有),分别使用args和kwargs参数中的顺序和关键字参数。``start():进程准备就绪,等待CPU调度。``join``([ 超时]):如果可选参数timeout是None,则该方法将阻塞,直到``join``()调用其方法的进程终止。如果timeout是一个正数,它最多会阻塞超时秒。 请注意,如果方法的进程终止或方法超时,则返回该方法。检查进程exitcode以确定它是否终止。``name:进程的名称。该名称是一个字符串,仅用于识别目的。``is_alive():返回进程是否存活。从start() 方法返回到子进程终止的那一刻,进程对象仍处于活动状态。``daemon:进程的守护进程标志,一个布尔值。必须在start()调用之前设置,当进程退出时,它会尝试终止其所有守护进程子进程。``pid:返回进程ID。在产生该过程之前,这将是 None。``exitcode:子进程的退出代码。None如果流程尚未终止,这将是。负值-N表示孩子被信号N终止。` |
**属性介绍**
| | |
|---|---|
| 123456789 | `p.daemon:默认值为False,如果设为True,代表p为后台运行的守护进程,当p的父进程终止时,p也随之终止,并且设定为True后,p不能创建自己的新进程,必须在p.start()之前设置``p.name:进程的名称``p.pid:进程的pid``p.exitcode:进程在运行时为None、如果为–N,表示被信号N结束(了解即可)``p.authkey:进程的身份验证键,默认是由os.urandom()随机生成的32字符的字符串。这个键的用途是为涉及网络连接的底层进程间通信提供安全性,这类连接只有在具有相同的身份验证键时才能成功(了解即可)` |
**需要注意的是start(),join(),is\_alive(), terminate()和exitcode方法只能由创建进程对象的过程调用。**
### 三 Process类的使用
**注意:在windows中Process()必须放到\# if \_\_name\_\_ == '\_\_main\_\_':下**
详细解释
| | |
|---|---|
| 123456789 | `Since Windows has no fork, the multiprocessing module starts a ``new` `Python process and imports the calling module.``If Process() gets called upon import, then ``this` `sets off an infinite succession of ``new` `processes (or until your machine runs ``out` `of resources).``This ``is` `the reason ``for` `hiding calls to Process() inside``if` `__name__ == ``"__main__"``since statements inside ``this` `if``-statement will not ``get` `called upon import.``由于Windows没有fork,多处理模块启动一个新的Python进程并导入调用模块。``如果在导入时调用Process(),那么这将启动无限继承的新进程(或直到机器耗尽资源)。``这是隐藏对Process()内部调用的原,使用``if` `__name__ == “__main __”,这个``if``语句中的语句将不会在导入时被调用。` |
**创建并开启子进程的两种方式**
**方法一:multiprocessing.Process子类化**
| | |
|---|---|
| 123456789101112131415 | `#开进程的方法一:``import time``import random``from` `multiprocessing import Process``def piao(name):`` ``print(``'%s piaoing'` `%name)`` ``time.sleep(random.randrange(1,5))`` ``print(``'%s piao end'` `%name)``p1=Process(target=piao,args=(``'egon'``,)) #必须加,号``p1.start()``print(``'主线程'``)` |
**方法二:通过函数**
| | |
|---|---|
| 1234567891011121314151617181920 | `#开进程的方法二:``import time``import random``from` `multiprocessing import Process``class` `Piao(Process):`` ``def __init__(self,name):`` ``super().__init__()`` ``self.name=name`` ``def run(self):`` ``print(``'%s piaoing'` `%self.name)`` ``time.sleep(random.randrange(1,5))`` ``print(``'%s piao end'` `%self.name)``p1=Piao(``'egon'``)``p1.start() #start会自动调用run``print(``'主线程'``)` |
****一些方法的示例用法:****
| | |
|---|---|
| 123456789101112131415161718192021222324 | `from` `multiprocessing import Process``import time``import os``def info():`` ``print(``'module name:'``, __name__)`` ``print(``'parent process:'``, os.getppid())`` ``print(``'process id:'``, os.getpid())``def f(name):`` ``info()`` ``time.sleep(3)`` ``print(``'hello'``, name)``if` `__name__ == ``'__main__'``:`` ``info()`` ``p = Process(target=f, args=(``'bob'``,))`` ``# p.daemon = False`` ``print(p.daemon)`` ``p.start()`` ``p.``join``(1)`` ``print(``'name:'``, p.name)`` ``print(``'is_alive:'``, p.is_alive())`` ``print(``'exitcode:'``, p.exitcode)` |
在上述逻辑中,子进程会休息3s然后再打印一句话才结束,同时设定join(1)阻塞1s,阻塞在1s后结束,我们的并没有守护主进程,然后主进程结束后,子进程依然alive;
如果想要守护主进程,设定p.daemon = True:
| | |
|---|---|
| 12345678910 | `if` `__name__ == ``'__main__'``:`` ``info()`` ``p = Process(target=f, args=(``'bob'``,))`` ``p.daemon = True`` ``print(p.daemon)`` ``p.start()`` ``# p.join(1)`` ``print(``'name:'``, p.name)`` ``print(``'is_alive:'``, p.is_alive())`` ``print(``'exitcode:'``, p.exitcode)` |
在上述逻辑中,子进程会休息3s然后再打印一句话才结束,我们的设定守护主进程,然后主进程结束后,打印的is\_alive: True这句话其实是在主进程里运行的,所以此时子进程确实是alive,但是主进程结束后子进程也结束了,不会运行info() 函数;
**进程直接的内存空间是隔离的**
| | |
|---|---|
| 123456789101112 | `from` `multiprocessing import Process``n=100 #在windows系统中应该把全局变量定义在``if` `__name__ == ``'__main__'``之上就可以了``def work():`` ``global n`` ``n=0`` ``print(``'子进程内: '``,n)``if` `__name__ == ``'__main__'``:`` ``p=Process(target=work)`` ``p.start()`` ``print(``'主进程内: '``,n)` |
对于要创建多个子进程的情形,更简洁的办法是采用进程池:multiprocessing.Pool(processes=None, initializer=None, initargs=(), maxtasksperchild=None)
| | |
|---|---|
| 1234 | `processes :使用的工作进程的数量,如果processes是None那么使用 os.cpu_count()返回的数量。``initializer: 如果initializer不是None,那么每一个工作进程在开始的时候会调用initializer(*initargs)。``maxtasksperchild:工作进程退出之前可以完成的任务数,完成后用一个新的工作进程来替代原进程,来让闲置的资源被释放。maxtasksperchild默认是None,意味着只要Pool存在工作进程就会一直存活。``context: 用在制定工作进程启动时的上下文,一般使用 multiprocessing.Pool() 或者一个context对象的Pool()方法来创建一个池,两种方法都适当的设置了context。 ` |
如,将socket通信变成并发的形式
**server.py**
| | |
|---|---|
| 123456789101112131415161718192021222324 | `from` `socket import *``from` `multiprocessing import Pool``server=socket(AF_INET,SOCK_STREAM)``server.setsockopt(SOL_SOCKET,SO_REUSEADDR,1)``server.bind((``'127.0.0.1'``,8080))``server.listen(5)``def talk(conn,):`` ``while` `True:`` ``try``:`` ``msg=conn.recv(1024)`` ``if` `not msg:``break`` ``conn.send(msg.upper())`` ``except Exception:`` ``break``if` `__name__ == ``'__main__'``: #windows下start进程一定要写到这下面`` ``pool = Pool(processes=10)`` ``while` `True:`` ``conn,client_addr=server.accept()`` ``pool.apply_async(talk,args=(conn,))` |
**client.py**
| | |
|---|---|
| 12345678910111213 | `from` `socket import *``client=socket(AF_INET,SOCK_STREAM)``client.connect((``'127.0.0.1'``,8080))``while` `True:`` ``msg=input(``'>>: '``).strip()`` ``if` `not msg:``continue`` ``client.send(msg.encode(``'utf-8'``))`` ``msg=client.recv(1024)`` ``print(msg.decode(``'utf-8'``))` |
### 四、僵尸进程与孤儿进程(了解)
| | |
|---|---|
| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 | `参考博客:http:``//www.cnblogs.com/Anker/p/3271773.html``一:僵尸进程(有害)`` 僵尸进程:一个进程使用fork创建子进程,如果子进程退出,而父进程并没有调用wait或waitpid获取子进程的状态信息,那么子进程的进程描述符仍然保存在系统中。这种进程称之为僵死进程。详解如下``我们知道在unix/linux中,正常情况下子进程是通过父进程创建的,子进程在创建新的进程。子进程的结束和父进程的运行是一个异步过程,即父进程永远无法预测子进程到底什么时候结束,如果子进程一结束就立刻回收其全部资源,那么在父进程内将无法获取子进程的状态信息。``因此,UNⅨ提供了一种机制可以保证父进程可以在任意时刻获取子进程结束时的状态信息:``1、在每个进程退出的时候,内核释放该进程所有的资源,包括打开的文件,占用的内存等。但是仍然为其保留一定的信息(包括进程号the process ID,退出状态the termination status of the process,运行时间the amount of CPU time taken ``by` `the process等)``2、直到父进程通过wait / waitpid来取时才释放. 但这样就导致了问题,如果进程不调用wait / waitpid的话,那么保留的那段信息就不会释放,其进程号就会一直被占用,但是系统所能使用的进程号是有限的,如果大量的产生僵死进程,将因为没有可用的进程号而导致系统不能产生新的进程. 此即为僵尸进程的危害,应当避免。`` 任何一个子进程(init除外)在exit()之后,并非马上就消失掉,而是留下一个称为僵尸进程(Zombie)的数据结构,等待父进程处理。这是每个子进程在结束时都要经过的阶段。如果子进程在exit()之后,父进程没有来得及处理,这时用ps命令就能看到子进程的状态是“Z”。如果父进程能及时 处理,可能用ps命令就来不及看到子进程的僵尸状态,但这并不等于子进程不经过僵尸状态。 如果父进程在子进程结束之前退出,则子进程将由init接管。init将会以父进程的身份对僵尸状态的子进程进行处理。``二:孤儿进程(无害)`` 孤儿进程:一个父进程退出,而它的一个或多个子进程还在运行,那么那些子进程将成为孤儿进程。孤儿进程将被init进程(进程号为1)所收养,并由init进程对它们完成状态收集工作。`` 孤儿进程是没有父进程的进程,孤儿进程这个重任就落到了init进程身上,init进程就好像是一个民政局,专门负责处理孤儿进程的善后工作。每当出现一个孤儿进程的时候,内核就把孤 儿进程的父进程设置为init,而init进程会循环地wait()它的已经退出的子进程。这样,当一个孤儿进程凄凉地结束了其生命周期的时候,init进程就会代表党和政府出面处理它的一切善后工作。因此孤儿进程并不会有什么危害。``我们来测试一下(创建完子进程后,主进程所在的这个脚本就退出了,当父进程先于子进程结束时,子进程会被init收养,成为孤儿进程,而非僵尸进程),文件内容``import os``import sys``import time``pid = os.getpid()``ppid = os.getppid()``print ``'im father'``, ``'pid'``, pid, ``'ppid'``, ppid``pid = os.fork()``#执行pid=os.fork()则会生成一个子进程``#返回值pid有两种值:``# 如果返回的pid值为0,表示在子进程当中``# 如果返回的pid值>0,表示在父进程当中``if` `pid > 0:`` ``print ``'father died..'`` ``sys.exit(0)``# 保证主线程退出完毕``time.sleep(1)``print ``'im child'``, os.getpid(), os.getppid()``执行文件,输出结果:``im father pid 32515 ppid 32015``father died..``im child 32516 1``看,子进程已经被pid为1的init进程接收了,所以僵尸进程在这种情况下是不存在的,存在只有孤儿进程而已,孤儿进程声明周期结束自然会被init来销毁。``三:僵尸进程危害场景:`` 例如有个进程,它定期的产 生一个子进程,这个子进程需要做的事情很少,做完它该做的事情之后就退出了,因此这个子进程的生命周期很短,但是,父进程只管生成新的子进程,至于子进程 退出之后的事情,则一概不闻不问,这样,系统运行上一段时间之后,系统中就会存在很多的僵死进程,倘若用ps命令查看的话,就会看到很多状态为Z的进程。 严格地来说,僵死进程并不是问题的根源,罪魁祸首是产生出大量僵死进程的那个父进程。因此,当我们寻求如何消灭系统中大量的僵死进程时,答案就是把产生大 量僵死进程的那个元凶枪毙掉(也就是通过kill发送SIGTERM或者SIGKILL信号啦)。枪毙了元凶进程之后,它产生的僵死进程就变成了孤儿进 程,这些孤儿进程会被init进程接管,init进程会wait()这些孤儿进程,释放它们占用的系统进程表中的资源,这样,这些已经僵死的孤儿进程 就能瞑目而去了。``四:测试``#1、产生僵尸进程的程序test.py内容如下``#coding:utf-8``from` `multiprocessing import Process``import time,os``def run():`` ``print(``'子'``,os.getpid())``if` `__name__ == ``'__main__'``:`` ``p=Process(target=run)`` ``p.start()`` ``print(``'主'``,os.getpid())`` ``time.sleep(1000)``#2、在unix或linux系统上执行``[root@vm172-31-0-19 ~]# python3 test.py &``[1] 18652``[root@vm172-31-0-19 ~]# 主 18652``子 18653``[root@vm172-31-0-19 ~]# ps aux |grep Z``USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND``root 18653 0.0 0.0 0 0 pts/0 Z 20:02 0:00 [python3] <defunct> #出现僵尸进程``root 18656 0.0 0.0 112648 952 pts/0 S+ 20:02 0:00 grep --color=auto Z``[root@vm172-31-0-19 ~]# top #执行top命令发现1zombie``top - 20:03:42 up 31 min, 3 users, load average: 0.01, 0.06, 0.12``Tasks: 93 total, 2 running, 90 sleeping, 0 stopped, 1 zombie``%Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st``KiB Mem : 1016884 total, 97184 free, 70848 used, 848852 buff/cache``KiB Swap: 0 total, 0 free, 0 used. 782540 avail Mem`` ``PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND ``root 20 0 29788 1256 988 S 0.3 0.1 0:01.50 elfin ``#3、``等待父进程正常结束后会调用wait/waitpid去回收僵尸进程``但如果父进程是一个死循环,永远不会结束,那么该僵尸进程就会一直存在,僵尸进程过多,就是有害的``解决方法一:杀死父进程``解决方法二:对开启的子进程应该记得使用``join``,``join``会回收僵尸进程``参考python2源码注释``class` `Process(``object``):`` ``def ``join``(self, timeout=None):`` ``''``'`` ``Wait until child process terminates`` ``''``'`` ``assert self._parent_pid == os.getpid(), ``'can only join a child process'`` ``assert self._popen ``is` `not None, ``'can only join a started process'`` ``res = self._popen.wait(timeout)`` ``if` `res ``is` `not None:`` ``_current_process._children.discard(self)``join``方法中调用了wait,告诉系统释放僵尸进程。discard为从自己的children中剔除``解决方法三:http:``//blog.csdn.net/u010571844/article/details/50419798` |
文章标签:
[Python](https://developer.aliyun.com/label/article_de-3-100008)
[Windows](https://developer.aliyun.com/label/article_de-3-100080)
[Unix](https://developer.aliyun.com/label/article_de-3-100078)
[Linux](https://developer.aliyun.com/label/article_de-3-100077)
[API](https://developer.aliyun.com/label/article_de-3-100252)
关键词:
[Python模块](https://www.aliyun.com/sswb/228218.html)
[Python multiprocessing模块](https://www.aliyun.com/sswb/222731.html)
[Python multiprocessing](https://www.aliyun.com/sswb/228287.html)
[](https://developer.aliyun.com/profile/rdjh36vsu32t6)
[1288912195458132](https://developer.aliyun.com/profile/rdjh36vsu32t6)
目录
相关文章
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
\|
5月前
\|
SQL 关系型数据库 数据库
[Python SQLAlchemy模块:从入门到实战的数据库操作指南](https://developer.aliyun.com/article/1686162)
免费提供Python+PyCharm编程环境,结合SQLAlchemy ORM框架详解数据库开发。涵盖连接配置、模型定义、CRUD操作、事务控制及Alembic迁移工具,以电商订单系统为例,深入讲解高并发场景下的性能优化与最佳实践,助你高效构建数据驱动应用。
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
713 7 7
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
\|
5月前
\|
监控 安全 程序员
[Python日志模块配置:从print到logging的优雅升级指南](https://developer.aliyun.com/article/1684548)
从 \`print\` 到 \`logging\` 是 Python 开发的必经之路。\`print\` 调试简单却难维护,日志混乱、无法分级、缺乏上下文;而 \`logging\` 支持级别控制、多输出、结构化记录,助力项目可维护性升级。本文详解痛点、优势、迁移方案与最佳实践,助你构建专业日志系统,让程序“有记忆”。
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
456 0 0
[dufadayang](https://developer.aliyun.com/profile/asptlxjl7zfxy)
\|
开发者 Python
[如何在Python中管理模块和包的依赖关系?](https://developer.aliyun.com/article/1641250)
在实际开发中,通常会结合多种方法来管理模块和包的依赖关系,以确保项目的顺利进行和可维护性。同时,要及时更新和解决依赖冲突等问题,以保证代码的稳定性和可靠性
[dufadayang](https://developer.aliyun.com/profile/asptlxjl7zfxy)
647 159 159
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
\|
5月前
\|
JSON 算法 API
[Python中的json模块:从基础到进阶的实用指南](https://developer.aliyun.com/article/1685589)
本文深入解析Python内置json模块的使用,涵盖序列化与反序列化核心函数、参数配置、中文处理、自定义对象转换及异常处理,并介绍性能优化与第三方库扩展,助你高效实现JSON数据交互。(238字)
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
547 4 4
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
\|
5月前
\|
Java 调度 数据库
[Python threading模块:多线程编程的实战指南](https://developer.aliyun.com/article/1686040)
本文深入讲解Python多线程编程,涵盖threading模块的核心用法:线程创建、生命周期、同步机制(锁、信号量、条件变量)、线程通信(队列)、守护线程与线程池应用。结合实战案例,如多线程下载器,帮助开发者提升程序并发性能,适用于I/O密集型任务处理。
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
571 0 0
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
\|
5月前
\|
XML JSON 数据处理
[超越JSON:Python结构化数据处理模块全解析](https://developer.aliyun.com/article/1685901)
本文深入解析Python中12个核心数据处理模块,涵盖csv、pandas、pickle、shelve、struct、configparser、xml、numpy、array、sqlite3和msgpack,覆盖表格处理、序列化、配置管理、科学计算等六大场景,结合真实案例与决策树,助你高效应对各类数据挑战。(238字)
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
704 0 0
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
\|
6月前
\|
安全 大数据 程序员
[Python operator模块的methodcaller:一行代码搞定对象方法调用的黑科技](https://developer.aliyun.com/article/1682589)
\`operator.methodcaller\`是Python中处理对象方法调用的高效工具,替代冗长Lambda,提升代码可读性与性能。适用于数据过滤、排序、转换等场景,支持参数传递与链式调用,是函数式编程的隐藏利器。
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
217 4 4
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
\|
6月前
\|
存储 数据库 开发者
[Python SQLite模块:轻量级数据库的实战指南](https://developer.aliyun.com/article/1683255)
本文深入讲解Python内置sqlite3模块的实战应用,涵盖数据库连接、CRUD操作、事务管理、性能优化及高级特性,结合完整案例,助你快速掌握SQLite在小型项目中的高效使用,是Python开发者必备的轻量级数据库指南。
[站大爷](https://developer.aliyun.com/profile/dwwc5b5sgkmkm)
557 0 0
[francisyu](https://developer.aliyun.com/profile/ywoa63qkikzuo)
\|
7月前
\|
存储 安全 数据处理
[Python 内置模块 collections 详解](https://developer.aliyun.com/article/1676831)
\`collections\` 是 Python 内置模块,提供多种高效数据类型,如 \`namedtuple\`、\`deque\`、\`Counter\` 等,帮助开发者优化数据处理流程,提升代码可读性与性能,适用于复杂数据结构管理与高效操作场景。
[francisyu](https://developer.aliyun.com/profile/ywoa63qkikzuo)
475 0 0
[游客fuyq5xtd5duvw](https://developer.aliyun.com/profile/fuyq5xtd5duvw)
\|
8月前
\|
数据安全/隐私保护 Python
[抖音私信脚本app,协议私信群发工具,抖音python私信模块](https://developer.aliyun.com/article/1673483)
这个实现包含三个主要模块:抖音私信核心功能类、辅助工具类和主程序入口。核心功能包括登录
[游客fuyq5xtd5duvw](https://developer.aliyun.com/profile/fuyq5xtd5duvw)
675 0 0
## 热门文章
## 最新文章
[1 Python开源游戏,《植物大战僵尸》](https://developer.aliyun.com/article/804860)
[2 python filter, map, 和reduce](https://developer.aliyun.com/article/524685)
[3 python多线程之Condition(条件变量)](https://developer.aliyun.com/article/234707)
[4 Py之Queue:python库之Queue的简介、安装、使用方法之详细攻略](https://developer.aliyun.com/article/796833)
[5 Python爬虫系列7-采集千图网无水印的VIP数据](https://developer.aliyun.com/article/974919)
[6 浅谈Python内置对象类型——数字篇(附py2和py3的区别之一)](https://developer.aliyun.com/article/764154)
[7 Python爬虫day2.3—python模块](https://developer.aliyun.com/article/651691)
[8 \[Python\]学习基础篇:文件和目录](https://developer.aliyun.com/article/507551)
[9 Python json模块dumps loads](https://developer.aliyun.com/article/320385)
[10 Python爬虫 爬取下载美国科研网站数据](https://developer.aliyun.com/article/986639)
[1 字典在Python中的应用与实例 381](https://developer.aliyun.com/article/1525929)
[2 元组(Tuple)在Python编程中的应用与实例 971](https://developer.aliyun.com/article/1525927)
[3 Python函数:深入理解与应用 171](https://developer.aliyun.com/article/1525924)
[4 Python中的try-except异常处理语句 1035](https://developer.aliyun.com/article/1525922)
[5 可移植性在Python中的优势 570](https://developer.aliyun.com/article/1525921)
[6 Python与C的联姻:探索Python的可移植性与C的底层力量 425](https://developer.aliyun.com/article/1525919)
[7 如何选择适合的Python并行计算库 336](https://developer.aliyun.com/article/1525735)
[8 如何优化Python代码以提高执行效率 139](https://developer.aliyun.com/article/1525730)
[9 Python编程的深入探索与实用案例 156](https://developer.aliyun.com/article/1525727)
[10 聊聊python多线程与多进程 217](https://developer.aliyun.com/article/1525725)
## 相关课程
[更多](https://edu.aliyun.com/explore/)
[Python爬虫实战](https://edu.aliyun.com/course/314078)
[Python开发基础入门](https://edu.aliyun.com/course/314083)
[Python常用数据科学库](https://edu.aliyun.com/course/314036)
[Python网络爬虫实战](https://edu.aliyun.com/course/313943)
[Python完全自学手册图文教程](https://edu.aliyun.com/course/313707)
[Python基础快速入门实战教程](https://edu.aliyun.com/course/313524)
## 相关电子书
[更多](https://developer.aliyun.com/ebook/)
[From Python Scikit-Learn to Sc](https://developer.aliyun.com/ebook/6027)
[Data Pre-Processing in Python:](https://developer.aliyun.com/ebook/7076)
[双剑合璧-Python和大数据计算平台的结合](https://developer.aliyun.com/ebook/7232)
## 推荐镜像
[更多](https://developer.aliyun.com/mirror/)
[python-release](https://developer.aliyun.com/mirror/python-release)
下一篇
[狂揽7.5k星!这款开源API网关彻底解放开发者:一键聚合GPT-4、Suno、Midjourney,还能在线充值!](https://developer.aliyun.com/article/1663800)
### 为什么选择阿里云
[什么是云计算](https://www.aliyun.com/about/what-is-cloud-computing)[全球基础设施](https://infrastructure.aliyun.com/)[技术领先](https://www.aliyun.com/why-us/leading-technology)[稳定可靠](https://www.aliyun.com/why-us/reliability)[安全合规](https://www.aliyun.com/why-us/security-compliance)[分析师报告](https://www.aliyun.com/analyst-reports)
### 大模型
[千问大模型](https://www.aliyun.com/product/tongyi)[大模型服务](https://bailian.console.aliyun.com/?tab=model#/model-market)[AI应用构建](https://bailian.console.aliyun.com/app-center?tab=app#/app-center)
### 产品和定价
[全部产品](https://www.aliyun.com/product/list)[免费试用](https://free.aliyun.com/)[产品动态](https://www.aliyun.com/product/news/)[产品定价](https://www.aliyun.com/price/detail)[配置报价器](https://www.aliyun.com/price/cpq/list)[云上成本管理](https://www.aliyun.com/price/cost-management)
### 技术内容
[技术解决方案](https://www.aliyun.com/solution/tech-solution)[帮助文档](https://help.aliyun.com/)[开发者社区](https://developer.aliyun.com/)[天池大赛](https://tianchi.aliyun.com/)[阿里云认证](https://edu.aliyun.com/)
### 权益
[免费试用](https://free.aliyun.com/)[解决方案免费试用](https://www.aliyun.com/solution/free)[高校计划](https://university.aliyun.com/)[5亿算力补贴](https://www.aliyun.com/benefit/form/index)[推荐返现计划](https://dashi.aliyun.com/?ambRef=shouYeDaoHang2&pageCode=yunparterIndex)
### 服务
[基础服务](https://www.aliyun.com/service)[企业增值服务](https://www.aliyun.com/service/supportplans)[迁云服务](https://www.aliyun.com/service/devopsimpl/devopsimpl_cloudmigration_public_cn)[官网公告](https://www.aliyun.com/notice/)[健康看板](https://status.aliyun.com/)[信任中心](https://security.aliyun.com/trust-center)
### 关注阿里云
关注阿里云公众号或下载阿里云APP,关注云资讯,随时随地运维管控云服务

联系我们:4008013260
[法律声明](https://help.aliyun.com/product/67275.html)[Cookies政策](https://terms.alicdn.com/legal-agreement/terms/platform_service/20220906101446934/20220906101446934.html)[廉正举报](https://aliyun.jubao.alibaba.com/)[安全举报](https://report.aliyun.com/)[联系我们](https://www.aliyun.com/contact)[加入我们](https://careers.aliyun.com/)
### 友情链接
[阿里巴巴集团](https://www.alibabagroup.com/cn/global/home)[淘宝网](https://www.taobao.com/)[天猫](https://www.tmall.com/)[全球速卖通](https://www.aliexpress.com/)[阿里巴巴国际交易市场](https://www.alibaba.com/)[1688](https://www.1688.com/)[阿里妈妈](https://www.alimama.com/index.htm)[飞猪](https://www.fliggy.com/)[阿里云计算](https://www.aliyun.com/)[万网](https://wanwang.aliyun.com/)[高德](https://mobile.amap.com/)[UC](https://www.uc.cn/)[友盟](https://www.umeng.com/)[优酷](https://www.youku.com/)[钉钉](https://www.dingtalk.com/)[支付宝](https://www.alipay.com/)[达摩院](https://damo.alibaba.com/)[淘宝海外](https://world.taobao.com/)[阿里云盘](https://www.aliyundrive.com/)[淘宝闪购](https://www.ele.me/)
© 2009-现在 Aliyun.com 版权所有 增值电信业务经营许可证: [浙B2-20080101](http://beian.miit.gov.cn/) 域名注册服务机构许可: [浙D3-20210002](https://domain.miit.gov.cn/%E5%9F%9F%E5%90%8D%E6%B3%A8%E5%86%8C%E6%9C%8D%E5%8A%A1%E6%9C%BA%E6%9E%84/%E4%BA%92%E8%81%94%E7%BD%91%E5%9F%9F%E5%90%8D/%E9%98%BF%E9%87%8C%E4%BA%91%E8%AE%A1%E7%AE%97%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%20)
[](https://zzlz.gsxt.gov.cn/businessCheck/verifKey.do?showType=p&serial=91330106673959654P-SAIC_SHOW_10000091330106673959654P1710919400712&signData=MEUCIQDEkCd8cK7%2Fyqe6BNMWvoMPtAnsgKa7FZetfPkjZMsvhAIgOX1G9YC6FKyndE7o7hL0KaBVn4f%20V%2Fiof3iAgpsV09o%3D)[浙公网安备 33010602009975号](http://www.beian.gov.cn/portal/registerSystemInfo)[浙B2-20080101-4](https://beian.miit.gov.cn/) |
| Readable Markdown | null |
| Shard | 149 (laksa) |
| Root Hash | 892221456919234349 |
| Unparsed URL | com,aliyun!developer,/article/1598648 s443 |