首页 > 系统相关 >多线程,多进程,协程,IO多路复用

多线程,多进程,协程,IO多路复用

时间:2023-10-31 09:44:52浏览次数:29  
标签:协程 Python 线程 IO 进程 多线程

关于Python

Python有多进程,且原生支持协程,但是由于GIL全局锁的存在,Python只有假多线程,即单线程轮流执行多个任务,常用于IO任务的阻塞等待当中。

多线程

即一种基于内核态工作的异步运行方式。对于多核CPU而言,只有多线程和多进程才能真正的充分调用CPU的多核工作。但是由于用户态向内核态切换时以及中断时的时间开销较大,一般只用于计算密集任务,不用于IO密集任务。

多进程

进程拥有独立的运行栈空间,相当于一个新的程序,一个进程可以有多个线程。进程也是基于内核态工作的。

多进程与多线程的区别

多线程实质是多任务,共享内存空间,线程间分享数据较为容易
多进程实质是多个独立程序,不共享内存空间,分享数据困难。多进程创建与销毁消耗资源与时间大于多线程。多进程与主进程交换数据时,必须对类进行序列化与反序列化,造成极大的性能损耗。

协程

Python与golang原生支持协程特性。协程的是用户态的多线程,即一个线程轮流执行多个任务,但相比于Python中的假多线程,协程并不真正创建线程,减少了内核态相关的损耗。
换言之,协程不是真正的异步。
多线程处理并行问题,协程处理并发问题。
协程的真正应用是IO并发领域,可以有效利用IO阻塞时间。

一图流概括

image

IO多路复用

文章链接:https://blog.csdn.net/Squid87/article/details/123452472

标签:协程,Python,线程,IO,进程,多线程
From: https://www.cnblogs.com/adamaik/p/17799568.html

相关文章

  • 论文阅读笔记——LAVA: Large-scale Automated Vulnerability Addition
    LAVA:Large-scaleAutomatedVulnerabilityAdditionBrendanDolan-Gavitt∗,PatrickHulin†,EnginKirda‡,TimLeek†,AndreaMambretti‡,WilRobertson‡,FrederickUlrich†,RyanWhelan†(Authorslistedalphabetically)∗[email protected]......
  • Markov Decision Process Model Based on Value Iteration
    TheoriesMarkovDecisionProcessGenerally,wenotesaMDPmodelas\((S,A,T_a,R_a,\gamma)\).Itstransitionfunctionis\(T_a(s,s')=\Pr(s_{t+1}|s_t=s,a_t=a)\),rewardfunctionis\(R_a(s,s')\).Andactionschoosingsatisfiesaspec......
  • 土地盐碱化Soil salinization
    土地盐碱化Soilsalinization1、TheDefinition:Itreferstotheprocessinwhichthesaltofthesoilbottomorgroundwaterrisestothesurfacewiththecapillarywater,andthesaltaccumulatesinthesurfacesoilafterthewaterevaporates.Referstothe......
  • 重新使用android studio编写udp socket程序,备忘记录
    1,建立socket需要使用子线程而不是主线程。2,java/android使用数据报格式。3,可以利用python作为socket的客户/服务器端,非常简单。但python可以不使用数据报,而直接使用字符串。当然也可以使用数据报。当与android配合时使用数据报格式4,一般地,传输的是字符串,因此,数字要编码为字符串......
  • Land pollution
    LandpollutionLandpollutionreferstothepollutantsproducedbyhumanactivitiesenterthesoilthroughvariousways,anditsquantityandspeedexceedthecapacityofthesoiltoholdandpurify,sothatthenature,compositionandcharacteristicsof......
  • Solution to OpenSSL Connection Problems With Github
    ProblemsUploadingFileswithGitSometimeswecanusegittooltosuccessfullyuploadprojectstoGithub,butinothertimeespeciallyafteraperiodofconfiguration,weoftenmeetthefollowingerror:OpenSSLSSL_read:Connectionwasreset,error10054......
  • 【Azure Function App】如何修改Azure函数应用的默认页面呢?
    问题描述当在Azure中创建了一个函数应用(FunctionApp)后,访问默认URL会得到一个默认的页面。是否有办法修改这个默认页面呢?  问题解答在之前的博文中,介绍了修改AppService的默认页面。1:【Azure应用服务】AppService默认页面暴露Tomcat版本信息,存在安全风险 :https://www.cnbl......
  • Plastic Pollution
    Causes:Madefrompolythene,plasticbagsinlandfillsitesaresupposedtolastbetweenaconservative200yearstoanestimated1millionyears.Over2billionbagsarebelievedtobedumpedeverydayinChina,wherethenon-degradablebagsareclogging......
  • C++多线程——async、packages_task、promise
    异步编程async、future基本概念和使用:异步执行函数:std::async可以异步执行一个函数,这意味着函数将在后台线程中执行,而当前线程可以继续执行其他任务。返回值获取:你可以获得函数的返回值,或者得到一个std::future对象,它允许你在将来的某个时刻获取函数的结果。线程......
  • Plastic pollution
    Whatisplasticpollution?Plasticpollution,alsoknownaswhitepollution,istheaccumulationinthe environment of synthetic plastic productstothepointthattheycreateproblemsforwildlifeandtheir habitats aswellasforthehuman populatio......