上传者: ruma23
|
上传时间:2020/6/4 5:34:08
|
文件大小:2.5MB
|
文件类型:pdf
asyncioRecipes.pdf
2019Apress出书ThePythonprogramminglanguageadoptedapreemptiveconcurrencyframeworkintheearly90sviathethreadingmodule,whichstrivedtomimictheJavaconcurrencylibrary,aspertherespectivecommitmessage.AsimplebutpowerfulmechanismgovernsconcurrentexecutionofbytecodeinmostPythonimplementations.ThismechanismiscalledtheGIL(globalinterpreterlock).Theinterpreterconsumesonebytecodeinstructionatatime.Thiseffectivelymeansthatonlyonethreadcanrunatthesametime(inoneinterpreterprocess).Despitethisfact,theunderlyingnativethreadimplementationmightbeabletorunmorethanonethreadatatime.Thethreadsareappointed“fair”amountsofCPUtime.Withoutemployingsophisticatedintrospectiontechniques,thisboilsdowntosimple/naivetime-basedschedulingalgorithms.Takingthisapproachinthepastwouldoftenyieldinferiorsolutionstoanequivalentsinglethreadedprogram,forPythonimplementationwithaGILlikeCPython.SinceremovingtheGILisnotanoption,1andpriorattemptslikePythonsafe-thread2failedbecausetheydegradedthesinglethreadingperformancesignificantly,theconcurrencysituationmeanthavingonlythethreadingmodule