Python multi-process understanding

background:

sort out

reference:

Thoroughly understand python processes and threads_哔哩哔哩_bilibili

Does multithreading execute multiple threads at the same time?

The difference between python multi-threaded multi-process and Java (sorting notes 9)

process:

进程是计算机分配资源的最小单位,线程是CPU执行的最小单位
不同于线程之间的资源共享,python中进程创建有三大模式fork,spawn,forkserver
主要关注于windows下的spawn 
spawn这个不支持线程锁,但是支持进程锁,需要关注一下

进程之间的数据共享可以通过四种方式来实现
1-c语言风格的代码[Value('i', 666)]
2-manager
3-队列
4-pipes
pipes和queue不会出现数据混乱
只有c语言那种方式和manager会出现混乱
实际开发中这种demo理论上应该很少,但是还需要实践
进程池的add_done_callback回调和线程池执行是有所区别的,回调是主进程执行
而线程池的回调是子主线程执行

issue concerned:

Why is python multithreading called pseudo multithreading? What is concurrency and parallelism?

Let's take the java language as an example. Java's multithreading can achieve concurrency and parallelism, but due to the existence of GIL, python can only achieve concurrency but not parallelism. If you want to achieve parallelism, then you need to use multi-processes, but the resource overhead of multi-processes is obviously greater than that of multi-threads. From the perspective of java, python's multi-threading is pseudo-multi-threading [because it only achieves concurrency, Parallelism cannot be achieved].

Guess you like

Origin blog.csdn.net/Elephantpretty/article/details/124288093