python 多进程的启动和代码执行顺序
对照着廖雪峰的网站学习Python遇到些问题:
在进程中,父进程创建子进程时发现,显示不是按照顺序显示,疑问?
参照代码如下:
from multiprocessing import Pool
import os, time, random def long_time_task(name):
print 'Run task %s (%s)...' % (name, os.getpid())
start = time.time()
time.sleep(random.random() * 3)
end = time.time()
print 'Task %s runs %0.2f seconds.' % (name, (end - start)) if __name__=='__main__':
print 'Parent process %s.' % os.getpid()
p = Pool()
for i in range(5):
p.apply_async(long_time_task, args=(i,))
print 'Waiting for all subprocesses done...'
p.close()
p.join()
print 'All subprocesses done.'
运行结果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAScAAAD+CAIAAAD3flRFAAAP/UlEQVR4nO3dP3qqThvGcVeUJltgBykt3ENKFmCfgsLaOli7ASvPdaW0+W1kmvctgGGYeQYGxQfQ76fKIf7NyZ1B4fbZ/A+Ars3cDwB4O5v/AOjaGAC6SB2gjdQB2kgdoI3UAdpIHaCN1AHaSB2gjdQB2kgdoI3UAdpIHaCN1AHaSB2gjdQB2oTU/fv377OrLEv9R7Zwv+VhczhsDuVvbMvt/HE4bA6HzfH8N9ejxCLJa93Pz48N29fX1+fn5/MeQRXyn5+f593F9C7lx/lmjPktD9uLuOW2P9bx+zsfq28BlflTV93XulL3W7ZLXGTLZdsucZdtedF5YFiFvtR5e5jenqe7xb18dQtVVsNLerfpXuzz8/Pfv3/Co7kWuyzL8zzLsizL8lO9Jcvyk/3CGGNO9SXqfxp7ud4t9lp2U7jFc9sfy/35uDkcNofj/hbdYtc6djLhGl7rrO/v7ypC3ner5Hx9fXlXryL0+fn5/f1tnDWtLEt3cfP+KboWuyYBp3xXXJttWf115xvmWuzykzHmlPtXuhZ5c4VT3kS1voz9XrjFd9keDvVO4+38cTz/CVuMuZSbw2FzOHyU5Qepg2NE6owx4lss4S6ot4JVgbRRvC91zbJjv3S2GeOGrvmWdwHjLHRZlrWJrZc257Lhlq52HTPmti/Pf8IWR/OSD6iMSJ3dXRTXOve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qk83G0anrtvLCVnh1E257OuxTh+3yzi33NLV7uts9DfSUa/U906Bh0NMTD+8Lry+Surqk7IVqfOoiffPqW34r3OmYBfVp/wVT2MIOO9dhm1toYSd0wFO62/f1xIX7whuQUyd23O7bwwz75tFWuJB1t87q3lHYwhYfW9byFqDou0Kp1wp+YF7jO7EnLtwXXp6cuvYPb+dVyujUiX3zaCvcWROCuw9XXb+FHTS1hVdY0uMZ7oCndLeDxve4njjeipS6U551a8z5qdNftp+ZM/xnOmxYe63wq7kW+W7XuRl/pZVX3vB1XdjUDtrc8ccjvdaKXyv+VJ1Pjknpifv3RSv8HSzxKPmrvasJdC0vdfVff/7g42UtL3XAqyN1gDZSB2gjdYA2UgdoI3WANlIHaCN1gDZSB2gjdYC2/wMcinDk1fEZZAAAAABJRU5ErkJggg==" alt="" />
可以看出代码执行是从if __name__=='__main__'开始执行,在执行15行调用long_time_task后,没有打印'Run task %s (%s)...'。
但是在15行p.apply_async(long_time_task, args=(i,)),加入 print ‘??’,会在'Waiting for all subprocesses done...',之前,打印‘’??‘’对这个很疑惑。
修改代码,让每个打印时,打印出时间:
from multiprocessing import Pool
import os, time, random def long_time_task(name):
print 'Run task %s (%s) at %f...' % (name, os.getpid(),time.time())
start = time.time()
time.sleep(random.random() * 3)
end = time.time()
print 'Task %s runs %0.2f seconds.' % (name, (end - start)) if __name__=='__main__':
print 'Parent process %s.' % os.getpid()
p = Pool()
for i in range(5):
p.apply_async(long_time_task, args=(i,))
print 'time:%s:' %time.time()
print 'parent: %f' %time.time()
print 'Waiting for all subprocesses done...'
p.close()
p.join()
print 'All subprocesses done.'
运行结果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcUAAAE1CAIAAAAZMWzKAAAgAElEQVR4nO2d27mjuhIGiccRrByIxIEQCHEQ2n4458EY1FL/LQnj61R962EGZKmRoS0uKoYBAAAAAAAAAAAAAAAAAAAAABLGaVmWZb5e5MppbCl/W77Y8td5SRGtAMCPcp1t/vhpLtd5mcZ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r+lvW/KBtdWof8z3Rz4F6OQj/aQeZ3hag/hFm1U/ZlP53npUnKP0ljkAAAJjSURBVJmqOB3zbr2eGmxSD4hysF6MYcUqCsinAF18op9UfOYMr2Dgrai1+cJ86sdZnE/so3O3wuK3agvD75+sh5kLC9DLJ/pJXU73tNr4RZvSj9lVvrceEWerUFU1RD4FeC4f6Sf1OMPTGsSvwnP9mPcFxSBXlY/qcVBxeq9GKZfv34G9SSjeZ7X3T34Lzf7e4IsDqPKRflIVog60ydOq4g/QN9hqnk27pvlGnS1cfCD8CqIvclseeWzNZYbJXkIlnwIAAAAAAAAAAAAAAAAAAAAAAAAAAAA8ne2R7+xJe7X8FFYDx9vf4fxZ4CUB+Akuwmmqlj/O0yr+avDmAXwF2nM6nJRPS4+n8pYOt3w6JlNIL1sN63TSLFLXi5q3a6dI+p5Q7RXVvldveX89PtpDethnyiAX4MkIz+mNx/Op8nhqX0mSLndJ6pBkYLP8Xm/uRVXeT+0J9b2iQfxdftJO76r0kHb6TGU8APAEpOd0Xfnw+NT3jQb5NI1hK6aWZx/3VqdFtNduydg+r3ypXX7SoB4P5c3r9e9F8QDAyVQ8pydfP7XjqbpPz+RTf3n2cbUllXzaeIFS+VLrftK2ekw4Z+RTLrwCvA7tOU3WP5RPlcdTeUtv/0lCSs73zTVEc75fBqO8n8oTqryiKv5eP2mnd1V6SDt9pjKerWJGrACnITynuW/U3j3qOH+UHk/PW3q7UngLY12133dKly/7+EtFo69j+J5QEWqLbLTFT9rtXVUe0l6fadQ0+RTgn4TnqAAATiAZQ3M1EAAAAAAAAAAAns//xB8AAPRBPgUAOAfyKQzD/wGGDAJNoh2zdQAAAABJRU5ErkJggg==" alt="" />
这样就找到原因了:
ps:在新代码中将原来的代码中long_time_task()创建子进程中的sleep删去。
parent首先运行,在调用刚创建子进程时,创建子进程已经创建好,然后继续执行后序代码,当子进程创建好后,显示子进程。
就是说子进程创建需要时间,在这个空闲时间,父线程继续执行代码,子进程创建完成后显示。
python 多进程的启动和代码执行顺序的更多相关文章
- Java代码执行顺序(静态变量,非静态变量,静态代码块,代码块,构造函数)加载顺序
//据说这是一道阿里巴巴面试题,先以这道题为例分析下 public class Text { public static int k = 0; public static Text t1 = new ...
- 当C#中带有return的TryCatch代码遇到Finally时代码执行顺序
编写的代码最怕出现的情况是运行中有错误出现,但是无法定位错误代码位置.综合<C#4.0图解教程>,总结如下: TryCatchFinally用到的最多的是TryCatch,Catch可以把 ...
- final、static、代码块、静态代码块、内部类、代码执行顺序
final final域使得确保初始化安全性(initialization safety)成为可能,初始化安全性让不可变形对象不需要同步就能自由地被访问和共享 作用在类上 ...
- [js]js代码执行顺序/全局&私有变量/作用域链/闭包
js代码执行顺序/全局&私有变量/作用域链 <script> /* 浏览器提供全局作用域(js执行环境)(栈内存) --> 1,预解释(仅带var的可以): 声明+定义 1. ...
- 浏览器环境下JavaScript脚本加载与执行探析之代码执行顺序
本文主要基于向HTML页面引入JavaScript的几种方式,分析HTML中JavaScript脚本的执行顺序问题 1. 关于JavaScript脚本执行的阻塞性 JavaScript在浏览器中被解析 ...
- Java中父类和子类代码执行顺序
执行顺序:父类静态块-->子类静态块-->父类非静态块-->父类构造方法-->子类非静态块-->子类构造方法 当父类或子类中有多个静态方法时按在代码中的顺序执行 pack ...
- 详解JavaScript的任务、微任务、队列以及代码执行顺序
摘要: 理解JS的执行顺序. 作者:前端小智 原文:详解JavaScript的任务.微任务.队列以及代码执行顺序 思考下面 JavaScript 代码: console.log("scrip ...
- python 代码执行顺序
Python代码在执行过程中,遵循下面的基本原则: 普通语句,直接执行: 碰到函数,将函数体载入内存,并不直接执行 碰到类,执行类内部的普通语句,但是类的方法只载入,不执行 碰到if.for等控制语句 ...
- javaScript代码执行顺序
javaScript是一种描述型脚本语言,由浏览器进行动态的解析和执行. 页面加载过程中,浏览器会对页面上载入的每个js代码块进行扫描. JavaScript是一段一段的分析执行的,在分析执行同一段代 ...
随机推荐
- Final互评------《飞词》---- 拉格朗日2018
一.基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评论作品的选题; N(Need,需求):拉格朗日2018团队对需求分析的做法是通过问卷调查的形式,通过问卷调查分析出目前的大学生群体 ...
- SCRUM 12.14
由于最近的课业较多,大家平时有些力不从心,对于工作完成得有限. 最近课业压力小了一些,我们决定从今天起,投入精力. 以下为我们的任务分配情况: 人员 任务 高雅智 清除缓存 彭林江 统计活跃用户数量 ...
- 2-Eighteenth Scrum Meeting-20151218
任务安排 成员 今日完成 明日任务 闫昊 写完学习进度记录的数据库操作 写完学习进度记录的数据库操作 唐彬 编写与服务器交互的代码 和服务器老师交流讨论区后台接口 史烨轩 获取视频url 尝试使用 ...
- LINUX基础实验报告
实验一:主要是介绍Linux系统概况,无运行代码. 实验二:Linux的基本操作 重要知识点 [Tab] 使用Tab键来进行命令补全,Tab键一般键盘是在字母Q旁边,这个技巧给你带来的最大的好处就是当 ...
- Linux内核分析(第六周)
进程的控制与创建 一.进程的描述 1.操作系统内核的三大功能:进程管理(核心),内存管理,文件系统: 2.状态: fork() task_zombit(终止) task_running(就绪:但是没有 ...
- Android的发展历程及搭建
Android的发展历程: 对于Android我比较不熟悉,因为我的第一只手机就是iphone,我没用过Android系统,但在中国使用带有Android系统的手机的人数是最多的,所以我想学习Andr ...
- node.js处理url常用方法
处理非阻塞I/O /* *回调函数的方法 异步 */ /* function f(cb){ fs.readFile('./4',(err,data)=>{ cb(data.toString()) ...
- js弹出层学习
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Windows server 自带的 .net版本
1. Win2012r2 所带的版本: 2. Win2016 所带的版本 4.6 Win2019 自带的 .net版本为: 4.7 4. 然后比较 Win2008r2sp1 使用的是 .net3.5 ...
- [转帖] 常见的cmd命令
记录一下 后期用的到. ------------ 1. Echo :显示当前ECHO的状态:ECHO ON 或者ECHO OFF .2. ECHO ON :ECHO状态设为ON,将显示命令行(如每行前 ...