进程,是系统进行资源分配最小单位(拥有独立的内存单元)。(python中多进程是真的)
线程,是操作系统最小的执行单位(共享内存资源),比进程还小。(python中多线程是假的,因为cpython解释器中的一个模块GIL(全局解释器锁),GIl功能和互斥锁相似。)
证明过程:
(一)多进程
import multiprocessing
import os
import time
def add2():
start_time = time.time()
for i in range(100000000):
pass
end_time = time.time()
use_time = end_time - start_time
print("进程id: %s use_time: %s" % (os.getpid(), use_time))
if __name__ == '__main__':
print("【进程测试】")
p1 = multiprocessing.Process(target=add2, args=(), name="p1-进程")
print("p1.name :%s" % p1.name)
p2 = multiprocessing.Process(target=add2, args=(), name="p2-进程")
start_time = time.time()
p1.start()
p2.start()
p1.join()
p2.join()
end_time = time.time()
use_time = end_time - start_time
print("主进程id:%s use_time: %s" % (os.getpid(),use_time))
print("====主进程单独运行一次循环耗时:=====")
add2()
多进程运行结果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdYAAACdCAIAAACGkM4WAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACOTSURBVHhe7V1Lkhw5ctVBZBpraYzUXdq44Dk0O1rzEn0CWt1gzkCuZDZzi9pwtjoDlRGIRDj8j/hn5iurRVUmPo4H9weH4/dvH//7P4/5/fDxy99//vrHn5+Oqe7itXz42/efP9///P03VU6KVRK3ZLKLw7JAPGC1ALQTszyiou4q87+d2BkvVfXQi//89vvHgXM/fPz05z9//bz/6+OQ7P7f/3z/+fP7/4zlv+wvsHrZrn/choOCjyOsD79/+8fPX//61/Cb5N+Rr4PZw82hLmX+/W8vzb/A6nFp6JUlBwUfR8GvrGdoOxAAAioCoGBQMBAAAkDgNASOoOBfv34V+q9/yNHA+ap38EwWVZIlE/fKgPRAAAgAgQwC3RR84yz5Q2uSpBZScC2wcGKyfJasysAEsEjWkioUIAMr0gABIAAEMghsQMGhS5shO4tAVUdVOrCUZ50xQB0q1PQWv2cwRRogAASAQBKBtRSsVkM5N+N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bJPq9kke+0eG3HOoRlncPjRjGm9Max32mcZjY4qBdOl3Wk8I5rplBxKxWK4o+LxAyOF2RW+Hvk3nOObg0oOSXbUomq4KdX9kEvR2wdejqOxhXDcKAnyFEy218yOcjN9KL07/Cj7gleaa5KCZzqrMjr7BLbzglm9024kuh2VnhklBsMnXwmxVSjaWPPMRE6vhRQ827Ah1co+pZ4LDz1rveZQsLoQN2M7a+ZN5IamnXp5+F6AoCZQ9hpOGelm7bJXUvy0WwiImfFD9ssOKG/QIgdJFuVTdr57x6bbjuhYBSm9fAkvOAwp1B6lNlxzaRoxfZZkcyQDAl0IHGM2XSIh8YMicIwupZbjehFUveDeQpAeCCxA4BizWSAYsjwcAsfo0i4U/HBYQ+CnQeAYs3kauNAQB4FjdAkU/FRvRmQsyt6cO8aIomWiTBUnpjnGbE5sIKo+DIFjdAkU/HIUfJgGn1LRMWZzStNQ6cEIHKNLoGBQ8FMhcIzZHMwFqO4UBI7RJVDwUxHQKZp6qUqPMZtLNRnC7ITAMboECgYFPxUCx5jNTjaPYi+FwDG6BAp+KgK6lAafIkwxG/wCga0Q2FuNQcGg4KdC4PtfwL9AYDMEbuoECn4qgti7O1E+EAACj4UAvGBQPBAAAkDgNARAwadB/1hjNaQFAkBgDwRAwaBgIAAEgMBpCICCT4N+jxEVZQIBIPBYCICCQcFAAAgAgdMQAAWfBv1jjdWQFggAgT0QAAWDgoEAEAACpyEACj4N+j1GVJQJBIDAYyEACgYFAwEgAAROQwAUfBr0jzVWQ1ogAAT2QAAUDAoGAkAACJyGACj4NOj3GFFRJhAAAo+FACgYFAwEgAAQOA2B/wfb6VM1bpZcsQAAAABJRU5ErkJggg==" alt="" />
(二)多线程
import threading
import time
def add2():
start_time = time.time()
for i in range(100000000):
pass
end_time = time.time()
use_time = end_time - start_time
print("线程id:%s 耗时:%s" % (threading.current_thread().ident, use_time))
if __name__ == '__main__':
print("【线程测试】")
print("主线程:%s 主线程id:%s" % (threading.current_thread(), threading.current_thread().ident))
t1 = threading.Thread(target=add2, args=(), name="t1-线程")
t2 = threading.Thread(target=add2, args=(), name="t2-线程")
start_time = time.time()
t1.start()
t2.start()
t1.join()
t2.join()
end_time = time.time()
use_time = end_time - start_time
print("线程id:%s 耗时:%s (主线程)" % (threading.current_thread().ident, use_time))
print("====主线程单独运行一次循环耗时:=====")
add2()
多线程运行结果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAmYAAACOCAIAAAAUxlMbAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAClVSURBVHhe7V1bjtw6ku2FDKZxZwb2bOZ+eC2GvRejtuL6mn3UDgaYz/7zSKKSCsXjMEgpMyszT6HR8E1RJOMwFCci+PrH1//+D/6PCBABIkAEiAARaCLwj2aJgQJ//vxRb5Vf7O+1GHjU24FkVc0u9bbL8kSACBABIvDcCHRT5sQ09s8lSPljpTGXz2qFhVZx/bIqWTJi34hBoy41O/DcCkHpiAARIAJEIELgBMps8mUUX2YIz33XBoiSF6MYN+qnW14RJxWICBABIkAEiMBRyrQIutFbJblCRYBlM4QXUWaUa41CWzD8pEx+G0SACBABIqAQOESZgC9rdOiGkmOUqZhPEqT9t9s3N+nqsrhKEVNviAARIAJEgAicSZkgMoviPPsKnkq0CdiIOJtDG81x1hczZN9shQWIABEgAkTgaRAYp0yc1XTjyIiEmuwlaUz9G1Am5rxMo7WGpxlvCkIEiAARIALDCJxPmSoQbMZqUV60Scn5xGwt2TtDScocViy+SASIABF4PgROpswodLMJVZv/LL9E040SekyWtg9u64wyn0+bKRERIAJE4KoInEmZlu1sQlURlSU/Nwdr+bKQK/h/95VavtIzBpdR5lWVj5UTASJABB4LgXHKjFb0RPK7CdguylQEdm3KbKaUH2uk2VsiQASIABE4iMDJlAl6Y7Oj9Rcw/WmJ1o1To5hSRpOSYjNRJinzoG7xdSJABIjAkyFwiDLBzKWiOkVXTdpTGVScZW3WJjsDQlXVCinzyXSd4hABIkAEDiJwlD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AL0KTlwGQZSIEqD/UDSJwGmUSys+PAE3e5x+jz9xD6s9nHh327WYInBNl3qy7bGgYAZq8Yej44oQA9YdqQAQYZc6LWV7kf8Xk8X9E4AgCL/KxUEwiECHAKPNVKPP3P8mXROAQAv/z7/9JS0oEXhwBUuarUOaLKzrFJwJEgAgcR4CUScokAkSACBABIpBCgJSZgum4b8IaiAARIAJE4NERIGWSMokAESACRIAIpBAgZaZgenTPiP0nAkSACBCB4wiQMkmZRIAIEAEiQARSCJAyUzAd901YAxEgAkSACDw6Av8PmPEB47NsploAAAAASUVORK5CYII=" alt="" />
(三)结论:
不论是线程还是进程,循环单独运行的时间都是差不多的4秒内。
而多线程的总耗时基本上是单独循环一次耗时的2倍左右,所以多线程是假的,是串行的。
- Python的进程与线程--思维导图
Python的进程与线程--思维导图
- Python创建进程、线程的两种方式
代码创建进程和线程的两种方式 """ 定心丸:Python创建进程和线程的方式基本都是一致的,包括其中的调用方法等,学会一个 另一个自然也就会了. "" ...
- Python基础-进程和线程
一.进程和线程的概念 首先,引出“多任务”的概念:多任务处理是指用户可以在同一时间内运行多个应用程序,每个应用程序被称作一个任务.Linux.windows就是支持多任务的操作系统,比起单任务系统它的 ...
- python中进程、线程、协程简述
进程 python中使用multiprocessing模块对进程进行操作管理 进程同步(锁.信号量.事件) 锁 —— multiprocessing.Lock 只要用到了锁 锁之间的代码就会变成同步的 ...
- python之进程与线程
什么是操作系统 可能很多人都会说,我们平时装的windows7 windows10都是操作系统,没错,他们都是操作系统.还有没有其他的? 想想我们使用的手机,Google公司的Androi ...
- Python 9 进程,线程
本节内容 python GIL全局解释器锁 线程 进程 Python GIL(Global Interpreter Lock) In CPython, the global interpreter l ...
- python之进程和线程2
1 GIL全局解释器锁定义 定义:在一个线程拥有了解释器的访问权后,其他的所有线程都必须等待他释放解释器的访问权,即这些线程的下一条指令并不会互相影响. 缺点:多处理器退化为单处理器 优点:避免大量 ...
- python之进程和线程
1 操作系统 为什么要有操作系统 ? 操作系统位于底层硬件与应用软件之间的一层 工作方式:向下管理硬件,向上提供接口 操作系统进程切换: 出现IO操作 固定时间 2 进程和线程的概念 进程就是一个程序 ...
- 《Python》进程收尾线程初识
一.数据共享 from multiprocessing import Manager 把所有实现了数据共享的比较便捷的类都重新又封装了一遍,并且在原有的multiprocessing基础上增加了新的机 ...
随机推荐
- Oracle DBA面试突击题
一份ORACLE DBA面试题 一:SQL tuning 类 1:列举几种表连接方式 答: Oracle的多表连接算法有Nest Loop.Sort Merge和Hash Join三大类,每一类又可以 ...
- hdu6121 Build a tree 模拟
/** 题目:hdu6121 Build a tree 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6121 题意:n个点标号为0~n-1:节点i的父节点 ...
- Spring MVC学习之三:处理方法返回值的可选类型
http://flyer2010.iteye.com/blog/1294400 ———————————————————————————————————————————————————————————— ...
- thymeleaf教程
本教程涵盖了常见的前端操作,比如,判断,循环,引入模板,常用函数(日期格式化,字符串操作)下拉,js和css中使用,基本可以应对一般场景. 怎么使用? 前端html页面标签中引入如下: <htm ...
- Canvas组件:画布,可以实现动画操作
Canvas组件:画布,可以实现动画操作. TextArea:文本域. 在单行文本域中回车会激发ActionEvent. 用CheckBoxGroup实现单选框功能. Java中,单选框和复选框都是使 ...
- 【cf492】D. Vanya and Computer Game(二分)
http://codeforces.com/contest/492/problem/D 有时候感觉人sb还是sb,为什么题目都看不清楚? x per second, y per second... 于 ...
- iOS 圆角投影
self.backgroundColor = [UIColor whiteColor]; self.layer.shadowColor = [UIColor lightGrayColor].CGCol ...
- TCP连接的建立与终止过程详解
TCP连接的建立与终止: 1.TCP连接的建立 设主机B运行一个服务器进程,它先发出一个被动打开命令,告诉它的TCP要准备接收客户进程的连续请求,然后服务进程就处于听的状态.不断检测是否有客 ...
- 【黑金原创教程】【TimeQuest】【第三章】TimeQuest 扫盲文
声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/al ...
- Arduino开发版学习计划--蓝牙控制小车行走
蓝牙模块一共6个引脚,我们一般只需要接4个线就可以了,分别是VCC.GND.TXD.RXD这四个引脚,我们分别接到arduino板子上,VCC接3.3V,GND接板子的GND,蓝牙TXD接板子的RXD ...