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
1