线程与进程
文章平均质量分 59
关于线程与进程的学习总结,2021年第一个专栏
忧郁奔向冷的天
力学,信号处理,数值计算,机器学习,编程。
I come from China and I'm interested in mathematics and physics.
I love programming.
I love to listen to and sing Cantonese songs.
I love keeping fit.
展开
-
线程、进程的概念(二)
在看代理模型就看到了代理模式内存管理引用计数:是指将资源的被引用次数保存起来,当被引用次数变为零时就将其释放的过程。垃圾回收:当某个程序占用的一部分内存空间不再被这个程序访问时,这个程序会借助垃圾回收算法向操作系统归还这部分内存空间。垃圾回收可以通过引用计数来实现,垃圾回收就是一种内存管理方式。内存管理,是指软件运行时对计算机内存资源的分配和使用的技术。其最主要的目的是如何高效、快速的分配,并且在适当的时候释放和回收内存资源。 可以想像一个很大的程序,当他运行时变成进程,而大部分的存储器空间原创 2021-01-04 20:36:18 · 79 阅读 · 0 评论 -
threading模块
推荐使用KiteThread多线程会有一个主线程与多个子线程。子线程就是通过Thread创建的线程。默认没有守护线程,当主线程执行结束后退出,不影响子线程的执行。设置子线程为守护线程时,主线程一旦执行结束,不论子线程是否执行完,直接终止子线程执行。在这种情况下,如果设置子线程同步,主线程会被阻塞,等到所有子线程执行结束,主线程才会执行结束。start启动线程joint同步线程,会阻塞主线程直到所有子线程执行完,如果设置了时间,超时后停止阻塞。setDaemon守护线程如果有需求,还可以原创 2021-01-02 21:47:23 · 123 阅读 · 0 评论 -
突破GIL
IMOOC,讲师链接https://www.imooc.com/t/5683545如何实现单进程多线程真正的并行1. 使用其他解释器2. 用C重写python线程创建的过程,就可以实现单进程多线程真正达到并行反之目前来看,Cpython的GIL仍将存在。双核CPU进行三种对比老师在虚拟机中的Ubuntu系统下运行三种情形:单进程多线程多进程调用c语言写的可执行文件具体说一下第三个:编译好c语言后可得到可执行文件,通过ctypes运行该可执行文件。可执行文件没有GIL。结原创 2021-01-02 11:14:58 · 132 阅读 · 0 评论 -
GIL的意义
只要是单进程不论是单还是多线程,无论是单核还是多核CPU,都是每次执行一个线程,前者是串行,后者是并发。只要是多进程就可以在多核CPU上并行,当然如果在单核CPU还是并发。为何不取消GIL?CPU bound:计算密集,CPU一直运作。使用多进程。IO bound:输入输出密集,CPU大部分时间是闲置,比如内存IO,网络IO,磁盘IO,sleep函数。使用单进程多线程与多进程单线程相比更省资源。补充1计算机有五部分:控制器、运算器,对应CPU存储器,对应内存条与硬盘输入设备,对原创 2021-01-02 10:17:23 · 108 阅读 · 0 评论 -
GIL
anaconda:包含conda与python以及一堆包。conda是一个IDE。miniconda:包含conda与python。pycharm:是一个IDE,所以安装pycharm后还需要安装python。原创 2021-01-01 21:34:48 · 114 阅读 · 4 评论 -
编译器与解释器
anaconda与pycharmanaconda:包含conda与python以及一堆包。conda是一个IDE。miniconda:包含conda与python。pycharm:是一个IDE,所以安装pycharm后还需要安装python。虚拟机python虚拟机:PVMjava虚拟机:JVM和VMware这种软件类似。编译器与解释器(我认为)原代码→编译器→ 机器码(可执行文件)→运行→结果原代码→解释器→ 字节码(pyc文件)→ 虚拟机→结果编译器优点:编译.原创 2021-01-01 18:31:41 · 228 阅读 · 0 评论 -
线程、进程的概念(一)
线程thread操作系统能够运算调度的最小单位。由操作系统内核调度的内核线程与由用户进程自行调度的用户线程或者混合调度。进程process进程是程序的实例,若干进程对应一个程序,进程被加载到存储器中。每个进程皆可以同步(循序)或异步(平行)的方式独立运行。在一个处理器上通过分时复用表现出平行运行的感觉,在多个处理器上真正平行运行。时分多路复用也称时间共享,分时复用。两个以上的信号轮流占用通道。多线程、多进程运行一个程序会有若干进程,每个进程会有若干线程。软件多线程:只有原创 2021-01-01 14:51:13 · 155 阅读 · 0 评论