进程与线程的区别
- Threads share the address space of the process that created it; processes have their own address space.
- Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process.
- Threads can directly communicate with other threads of its process; processes must use interprocess communication to communicate with sibling processes.
- New threads are easily created; new processes require duplication of the parent process.
- Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes.
- Changes to the main thread (cancellation, priority change, etc.) may affect the behavior of the other threads of the process; changes to the parent process does not affect child processes.
1、进程创建线程,线程共享进程的地址空间; 进程具有自己的地址空间。
2、线程可以直接访问进程的数据段。 进程只有其父进程数据段的副本。
3、线程可以直接与其进程中的其他线程通信。 进程必须使用进程间通信与同级进程进行通信。
4、进程创建新线程很容易; 新进程需要父进程创建一个子进程,复制一份内存空间
5、线程可以对同一进程的线程进行相当多的控制。 进程只能控制子进程。
6、主线程的更改(取消,优先级更改等)可能会影响该进程其他线程的行为; 对父进程的更改不会影响子进程。
python多线程不适合cpu密集操作型的任务,适合io操作密集型的任务
多线程就是启用多个进程,每个进程至少有一个线程,就有8个线程,但是这8个线程之间是隔离的
Python学习之进程与线程的区别
原文:https://www.cnblogs.com/wengshaohang/p/12358846.html