-èŠããã«ãã©ã®ãããªèšç»ããããŸããïŒãŸããPythonãåŠã¶çç±ã«ã€ããŠèª¬æããŸãã次ã«ãCPythonã€ã³ã¿ãŒããªã¿ãŒãã©ã®ããã«æ©èœããããã¡ã¢ãªãã©ã®ããã«ç®¡çããããPythonã®åã·ã¹ãã ãã©ã®ããã«æ©èœããããèŸæžããžã§ãã¬ãŒã¿ãŒãããã³äŸå€ãèŠãŠã¿ãŸããããïŒæéãããããããšæããŸãã
- ãªãPythonãªã®ãïŒ
- éèš³è£ çœ®
- ã¿ã€ãã³ã°
- èŸæž
- ã¡ã¢ãªç®¡ç
- ãžã§ãã¬ãŒã¿ãŒ
- äŸå€
ãªãPythonãªã®ãïŒ
* Insights.stackoverflow.com/survey/2019**
éåžžã«äž»èŠ³çãª
***ç 究ã®
解é****ç 究ã®è§£é
å§ããŸãããããªãPythonãªã®ãïŒã¹ã©ã€ãã¯ãããã¯ãšã³ãéçºã§çŸåšäœ¿çšãããŠããããã€ãã®èšèªã®æ¯èŒã瀺ããŠããŸããããããèŠããã«ãPythonã®å©ç¹ã¯äœã§ããïŒããªãã¯ããã«ããã«ã³ãŒããæžãããšãã§ããŸãããã¡ãããããã¯éåžžã«äž»èŠ³çãªãã®ã§ããã¯ãŒã«ãªC ++ãŸãã¯Goãäœæãã人ã¯ãããã«ã€ããŠè°è«ããããšãã§ããŸããããããå¹³åããŠãPythonã§ã®æžã蟌ã¿ã¯é«éã§ãã
æ¬ ç¹ã¯äœã§ããïŒæåã®ããããŠããããäž»ãªæ¬ ç¹ã¯ãPythonãé ãããšã§ããä»ã®èšèªããã30åé ããªãå¯èœæ§ããããŸããããã¯ããã®ãããã¯ã«é¢ãã調æ»ã§ãããããããã®é床ã¯ã¿ã¹ã¯ã«ãã£ãŠç°ãªããŸããã¿ã¹ã¯ã«ã¯2ã€ã®ã¯ã©ã¹ããããŸãã
-CPUããŠã³ããCPUããŠã³ãã¿ã¹ã¯ãCPUããŠã³ãã
--I / Oãã€ã³ããã¿ã¹ã¯ã¯å ¥åºåã«ãã£ãŠå¶éãããŸãïŒãããã¯ãŒã¯çµç±ãŸãã¯ããŒã¿ããŒã¹å ã
CPUã«ãã€ã³ããããåé¡ã解決ããŠããå Žåã¯ãã¯ããPythonã¯é ããªããŸãã I / Oããã€ã³ããããŠããŠãããã倧ããªã¯ã©ã¹ã®ã¿ã¹ã¯ã§ããå Žåãå®è¡é床ãç解ããã«ã¯ããã³ãããŒã¯ãå®è¡ããå¿ èŠããããŸãããããŠãããããPythonãä»ã®èšèªãšæ¯èŒããŠããããã©ãŒãã³ã¹ã®éãã«æ°ä»ãããšãããããŸããã
ããã«ãPythonã¯åçã«åä»ããããŸããã€ã³ã¿ãŒããªã¿ãŒã¯ãã³ã³ãã€ã«æã«åããã§ãã¯ããŸãããããŒãžã§ã³3.5ã§ã¯ãã¿ã€ããã³ãã衚瀺ãããã¿ã€ããéçã«æå®ã§ããŸãããããã»ã©å³å¯ã§ã¯ãããŸãããã€ãŸããã³ã³ãã€ã«æ®µéã§ã¯ãªãããã§ã«æ¬çªç°å¢ã§ãšã©ãŒãçºçããå¯èœæ§ããããŸããããã¯ãšã³ãçšã®ä»ã®äžè¬çãªèšèªïŒJavaãCïŒãC ++ãGoïŒã«ã¯éçåä»ãããããŸãïŒã³ãŒãã§ééã£ããªããžã§ã¯ããæž¡ããšãã³ã³ãã€ã©ãŒããã®ããšãéç¥ããŸãã
ãã£ãšçŸå®çã«èšãã°ãPythonã¯ã¿ã¯ã·ãŒè£œåéçºã§ã©ã®ããã«äœ¿çšãããŠããŸããïŒç§ãã¡ã¯ãã€ã¯ããµãŒãã¹ã¢ãŒããã¯ãã£ã«åãã£ãŠããŸããç§ãã¡ã¯ãã§ã«160ã®ãã€ã¯ããµãŒãã¹ãã€ãŸãé£æåãæã£ãŠããŸã-35ãPythonã§15ããã©ã¹ã§20ãã€ãŸããçŸåšãPythonã®ã¿ããŸãã¯ãã©ã¹ã§èšè¿°ããŠããŸãã
ã©ã®ããã«èšèªãéžæããŸããïŒ1ã€ç®ã¯è² è·èŠä»¶ã§ããã€ãŸããPythonããããåŠçã§ãããã©ããã確èªããŸãã圌ãåŒã£åŒµã£ãå Žåãç§ãã¡ã¯ããŒã éçºè ã®èœåãèŠãŸãã
ããã§ã¯éèš³ã«ã€ããŠã話ããããšæããŸããCPythonã¯ã©ã®ããã«æ©èœããŸããïŒ
éèš³è£ çœ®
çåãçãããããããŸããïŒãªãéèš³ãã©ã®ããã«æ©èœããããç¥ãå¿ èŠãããã®ã§ããã質åã¯æå¹ã§ããå éšã«äœãããããç¥ããªããŠããç°¡åã«ãµãŒãã¹ãäœæã§ããŸããçãã¯æ¬¡ã®ãšããã§ã
ã1ãé«è² è·ã®æé©åãPythonãµãŒãã¹ããããšæ³åããŠãã ãããããã¯åäœããè² è·ã¯äœãã§ããããããããæ¥ãä»äºãããªãã«ãã£ãŠæ¥ãŸã-éãè² è·ã«åããŠãã³ãæžãããšã§ããããããéããããšã¯ã§ããŸãããC++ã§ãµãŒãã¹å šäœãæžãçŽãããšã¯ã§ããŸããããããã£ãŠãé«è² è·çšã«ãµãŒãã¹ãæé©åããå¿ èŠããããŸããã€ã³ã¿ããªã¿ãã©ã®ããã«æ©èœããããç解ãããšãããã«åœ¹ç«ã¡ãŸãã
2.è€éãªã±ãŒã¹ã®ãããã°ããµãŒãã¹ã¯å®è¡ãããŠããããã¡ã¢ãªãããªãŒã¯ããå§ãããšããŸãã Yandex.Taxiã§ã¯ãã€ãæè¿ãã®ãããªã±ãŒã¹ãçºçããŸããããã®ãµãŒãã¹ã¯1æéããšã«8GBã®ã¡ã¢ãªãæ¶è²»ããã¯ã©ãã·ã¥ããŸãããç§ãã¡ã¯ãããç解ããå¿ èŠããããŸããããã¯èšèªãPythonã«ã€ããŠã§ãã Pythonã§ã¡ã¢ãªç®¡çãã©ã®ããã«æ©èœãããã«ã€ããŠã®ç¥èãå¿ èŠã§ãã
3.ããã¯ãè€éãªã©ã€ãã©ãªãè€éãªã³ãŒããäœæããå Žåã«åœ¹ç«ã¡ãŸãã
4.ãããŠäžè¬çã«-ãŠãŒã¶ãŒãšããŠã ãã§ãªããããæ·±ãã¬ãã«ã§äœæ¥ããŠããããŒã«ãç¥ãããšã¯è¯ã圢ã§ãããšèããããŠããŸããããã¯Yandexã§é«ãè©äŸ¡ãããŠããŸãã
5.圌ãã¯ã€ã³ã¿ãã¥ãŒã§ããã«ã€ããŠè³ªåããŸãããããã¯éèŠã§ã¯ãããŸããããããªãã®äžè¬çãªITã®èŠéãã§ãã
翻蚳è ã®çš®é¡ãç°¡åã«æãåºããŠã¿ãŸããããã³ã³ãã€ã©ãŒãšã€ã³ã¿ãŒããªã¿ãŒããããŸãããåç¥ãããããŸããããã³ã³ãã€ã©ã¯ããœãŒã¹ã³ãŒããçŽæ¥ãã·ã³ã³ãŒãã«å€æãããã®ã§ããããããã€ã³ã¿ããªã¿ã¯æåã«ãã€ãã³ãŒãã«å€æãã次ã«ãããå®è¡ããŸãã Pythonã¯è§£éãããèšèªã§ãã
Bytecodeã¯ããªãªãžãã«ããååŸãããäžçš®ã®äžéã³ãŒãã§ãããã©ãããã©ãŒã ã«é¢é£ä»ããããŠããããä»®æ³ãã·ã³äžã§å®è¡ãããŸãããªãä»®æ³ãªã®ãïŒããã¯æ¬ç©ã®è»ã§ã¯ãããŸããããããçš®ã®æœè±¡åã§ãã
ã©ã®ãããªçš®é¡ã®ä»®æ³ãã·ã³ããããŸããïŒç»é²ããŠã¹ã¿ãã¯ããŸããããããããã§ã¯ãããã§ã¯ãªããPythonãã¹ã¿ãã¯ãã·ã³ã§ãããšããäºå®ãèŠããŠããå¿ èŠããããŸãã次ã«ãã¹ã¿ãã¯ãã©ã®ããã«æ©èœãããã確èªããŸãã
ãããŠãã1ã€ã®æ³šæç¹ïŒããã§ã¯CPythonã«ã€ããŠã®ã¿èª¬æããŸãã CPythonã¯ããæ³åã®ãšãããCã§èšè¿°ããããªãã¡ã¬ã³ã¹Pythonå®è£ ã§ããå矩èªãšããŠäœ¿çšãããŸããPythonã«ã€ããŠè©±ããšãã¯ãéåžžãCPythonã«ã€ããŠè©±ããŸãã
ããããä»ã®éèš³ãããŸãã JITã³ã³ãã€ã«ã䜿çšããŠçŽ5åé«éåããPyPyããããŸãããã£ãã«äœ¿çšãããŸãããç§ã¯æ£çŽã«äŒã£ãããšããããŸããã JPythonããããJavaä»®æ³ãã·ã³ãšDotnetãã·ã³ã®ãã€ãã³ãŒããå€æããIronPythonããããŸããããã¯ä»æ¥ã®è¬çŸ©ã®ç¯å²å€ã§ã-æ£çŽãªãšãããç§ã¯ããã«ééããŠããŸãããããã§ã¯ãCPythonãèŠãŠã¿ãŸãããã
ãã°ããæ§åãèŠãŠã¿ãŸãããããœãŒã¹ãè¡ãããããããå®è¡ããããéèš³ã¯äœãããŸããïŒæååã¯åãªãæåã®éãŸãã§ããããã§äœãæå³ã®ããããšãããããã«ãããªãã¯æåã«ã³ãŒããããŒã¯ã³ã«ç¿»èš³ããŸããããŒã¯ã³ã¯ãæåã®ã°ã«ãŒãåãããã»ãããèå¥åãæ°åããŸãã¯ããçš®ã®å埩ã§ããå®éãã€ã³ã¿ããªã¿ã¯ã³ãŒããããŒã¯ã³ã«å€æããŸãã
ããã«ãæœè±¡æ§æããªãŒASTã¯ããããã®ããŒã¯ã³ããæ§ç¯ãããŸãããŸãããŸã æ°ã«ããªãã§ãã ããããããã¯ãæäœãè¡ãããŒãå ã®äžéšã®ããªãŒã§ãããã®å Žåããã€ããªæäœã§ããBinOpããããšããŸããããæäœ-ææ°ããªãã©ã³ãïŒäžããæ°ãäžããåã
ããã«ããããã®ããªãŒã䜿çšããŠããã§ã«ããã€ãã®ã³ãŒããäœæã§ããŸããç§ã¯å€ãã®ã¹ããããéããŸããæé©åã¹ããããä»ã®ã¹ãããããããŸãã次ã«ããããã®æ§æããªãŒããã€ãã³ãŒãã«å€æãããŸãã
ããã§ãã£ãšè©³ããèŠãŠã¿ãŸãããã Bytecodeã¯ããã®ååã瀺ãããã«ããã€ãã§æ§æãããã³ãŒãã§ãããŸããPythonã§ã¯ã3.6以éããã€ãã³ãŒãã¯2ãã€ãã§ãã
æåã®ãã€ãã¯ãopcodeãšåŒã°ããæŒç®åèªäœã§ãã 2çªç®ã®ãã€ãã¯opargåŒæ°ã§ããäžããèŠãããã§ããã€ãŸããäžé£ã®ãã€ãã§ããããããPythonã«ã¯Disassemblerã®disãšããã¢ãžã¥ãŒã«ããããããã䜿çšãããšããã人éãèªã¿ãããè¡šçŸãèŠãããšãã§ããŸãã
ããã¯ã©ã®ããã«èŠããŸããïŒãœãŒã¹ã®è¡çªå·ããããŸã-巊端ã®çªå·ã§ãã 2çªç®ã®åã¯ã¢ãã¬ã¹ã§ããç§ãèšã£ãããã«ãPython 3.6ã®ãã€ãã³ãŒãã¯2ãã€ããåãã®ã§ããã¹ãŠã®ã¢ãã¬ã¹ã¯å¶æ°ã§ãã
ã0ã2ã4ã衚瀺ãããŸã... Load.nameãLoad.constã¯ãã§ã«ã³ãŒããªãã·ã§ã³èªäœã§ãã Pythonãå®è¡ãããŸãã 0ã0ã1ã1ã¯opargãã€ãŸããããã®æäœã®åŒæ°ã§ãã次ã«ãããããã©ã®ããã«å®è¡ãããããèŠãŠã¿ãŸãããã
ïŒ...ïŒãã€ãã³ãŒããPythonã§ã©ã®ããã«å®è¡ããããããã®ããã«ã©ã®ãããªæ§é ãããããèŠãŠã¿ãŸãããã
CãããããªããŠã倧äžå€«ã§ããè泚ã¯äžè¬çãªç解ã®ããã®ãã®ã§ãã
Pythonã«ã¯ããã€ãã³ãŒãã®å®è¡ã«åœ¹ç«ã€2ã€ã®æ§é ããããŸãã 1ã€ç®ã¯CodeObjectã§ããã®æŠèŠã確èªã§ããŸããå®éãæ§é ã¯ãã倧ãããªã£ãŠããŸããããã¯ã³ã³ããã¹ãã®ãªãã³ãŒãã§ããããã¯ããã®æ§é ã«å®éã«ä»èŠããã€ãã³ãŒããå«ãŸããŠããããšãæå³ããŸããé¢æ°ã«å®æ°ãžã®åç §ãå®æ°ã®ååãªã©ãå«ãŸããŠããå Žåã¯ããã®é¢æ°ã§äœ¿çšãããå€æ°ã®ååãå«ãŸããŸãã
次ã®æ§é ã¯FrameObjectã§ããããã¯ãã§ã«å®è¡ã³ã³ããã¹ãã§ãããå€æ°ã®å€ããã§ã«å«ãŸããŠããæ§é ã§ããã°ããŒãã«å€æ°ãžã®åç §ãå®è¡ã¹ã¿ãã¯ïŒããã«ã€ããŠã¯åŸã§èª¬æããŸãïŒãããã³ãã®ä»ã®å€ãã®æ å ±ãåœä»€ã®å®è¡åæ°ãèããŠã¿ãŸãããã
äŸãšããŠãé¢æ°ãè€æ°ååŒã³åºãããå Žåã¯ãåãCodeObjectããããåŒã³åºãããšã«æ°ããFrameObjectãäœæãããŸããç¬èªã®åŒæ°ãç¬èªã®ã¹ã¿ãã¯ããããŸãããããã£ãŠããããã¯çžäºæ¥ç¶ãããŠããŸãã
ã¡ã€ã³ã®ã€ã³ã¿ãŒããªã¿ãŒã«ãŒããšã¯äœã§ããïŒãã€ãã³ãŒãã¯ã©ã®ããã«å®è¡ãããŸããïŒããªãã¯ç§ãã¡ãopargã§ãããã®opcodeã®ãªã¹ããæã£ãŠããã®ãèŠãŸãããããã¯ã©ã®ããã«è¡ãããŸããïŒ Pythonã«ã¯ãä»ã®ã€ã³ã¿ãŒããªã¿ãŒãšåæ§ã«ããã®ãã€ãã³ãŒããå®è¡ããã«ãŒãããããŸããã€ãŸãããã¬ãŒã ããã¬ãŒã ã«å ¥ããPythonã¯ãã€ãã³ãŒããé çªã«èª¿ã¹ããããã©ã®ãããªçš®é¡ã®opargã§ãããã調ã¹ã巚倧ãªã¹ã€ããã䜿çšããŠãã³ãã©ãŒã«ç§»åããŸããããšãã°ãããã§ã¯1ã€ã®opcodeã®ã¿ã瀺ãããŠããŸããããšãã°ãããã«ãã€ããªæžç®ããã€ããªæžç®ããããŸããããšãã°ããã®å Žæã§ãABããå®è¡ããããšããŸãã
ãã€ããªæžç®ãã©ã®ããã«æ©èœãããã説æããŸããããéåžžã«åçŽã§ãããã¯æãåçŽãªã³ãŒãã®1ã€ã§ãã TOPé¢æ°ã¯ãã¹ã¿ãã¯ããæäžäœã®å€ãååŸããæäžäœã®å€ããååŸããã¹ã¿ãã¯ãããããããã ãã§ãªããPyNumber_Subtracté¢æ°ãåŒã³åºãããŸããçµæïŒã¹ã©ãã·ã¥SET_TOPé¢æ°ãã¹ã¿ãã¯ã«ããã·ã¥ããã¯ãããŸããã¹ã¿ãã¯ã«ã€ããŠæ確ã§ãªãå Žåã¯ãäŸã次ã«ç€ºããŸãã
GILã«ã€ããŠç°¡åã«èª¬æããŸãã GILã¯ãPythonã®ããã»ã¹ã¬ãã«ã®ãã¥ãŒããã¯ã¹ã§ããããã®ãã¥ãŒããã¯ã¹ãã¡ã€ã³ã®ã€ã³ã¿ãŒããªã¿ãŒã«ãŒãã«åã蟌ã¿ãŸãããã®åŸããã€ãã³ãŒãã®å®è¡ãéå§ãããŸããããã¯ãã€ã³ã¿ãŒããªã¿ãŒã®å éšæ§é ãä¿è·ããããã«ãäžåºŠã«1ã€ã®ã¹ã¬ããã®ã¿ããã€ãã³ãŒããå®è¡ããããã«è¡ãããŸãã
ããå°ãé²ãã§ãPythonã®ãã¹ãŠã®ãªããžã§ã¯ãã«ããããžã®åç §ãããã€ããããšããŸãããããŸãã2ã€ã®ã¹ã¬ããããã®ãªã³ã¯æ°ãå€æŽãããšãã€ã³ã¿ãŒããªã¿ãŒãæ©èœããªããªããŸãããããã£ãŠãGILããããŸãã
ããã«ã€ããŠã¯ãéåæããã°ã©ãã³ã°ã«é¢ããè¬çŸ©ã§èª¬æããŸããããã¯ããªãã«ãšã£ãŠã©ã®ããã«éèŠã§ããïŒãã«ãã¹ã¬ããã¯äœ¿çšãããŸãããè€æ°ã®ã¹ã¬ãããäœæããå Žåã§ããéåžžã¯ãã®ãã¡ã®1ã€ã ããå®è¡ããããã€ãã³ãŒãã¯ã¹ã¬ããã®1ã€ã§å®è¡ãããããã§ãããããã£ãŠããã«ãããã»ãã·ã³ã°ãsishæ¡åŒµããŸãã¯ä»ã®äœãã䜿çšããŠãã ããã
ç°¡åãªäŸããã®ãã¬ãŒã ã¯Pythonããå®å šã«æ¢çŽ¢ã§ããŸããã¢ã³ããŒã¹ã³ã¢é¢æ°get_frameãæã€sysã¢ãžã¥ãŒã«ããããŸãããã¬ãŒã ãååŸããŠãããã«ããå€æ°ã確èªã§ããŸããæ瀺ããããŸããããã¯æããããã®ãã®ã§ãå®éã«ã¯äœ¿çšããŸããã§ããã
ç解ããããã«ãPythonä»®æ³ãã·ã³ã¹ã¿ãã¯ãã©ã®ããã«æ©èœããããèŠãŠã¿ãŸããããäœãããã®ãç解ã§ããªãéåžžã«åçŽãªã³ãŒããããã€ããããŸãã
å·ŠåŽã¯ã³ãŒãã§ããçŸåšèª¿æ»äžã®éšåã¯é»è²ã§åŒ·èª¿è¡šç€ºãããŠããŸãã 2çªç®ã®åã«ã¯ããã®éšåã®ãã€ãã³ãŒãããããŸãã 3çªç®ã®åã«ã¯ãã¹ã¿ãã¯ã®ãããã¬ãŒã ãå«ãŸããŠããŸããã€ãŸããåFrameObjectã«ã¯ç¬èªã®å®è¡ã¹ã¿ãã¯ããããŸãã
Pythonã¯äœãããŸããïŒããã¯é çªã«é²ã¿ãäžå€®ã®åã®ãã€ãã³ãŒããå®è¡ãããã¹ã¿ãã¯ã§æ©èœããŸãã
LOAD_CONSTãšåŒã°ããæåã®opcodeãå®è¡ããŸãããå®æ°ãããŒãããŸãããã®éšåãã¹ãããããããã«CodeObjectãäœæãããå®æ°ã®ã©ããã«CodeObjectããããŸããã Pythonã¯ãLOAD_CONSTã䜿çšããŠã¹ã¿ãã¯ã«ããŒãããŸãããããã§ããã®ãã¬ãŒã ã®ã¹ã¿ãã¯ã«CodeObjectãã§ããŸãããå ã«é²ãããšãã§ããŸãã
次ã«ãPythonã¯opcodeMAKE_FUNCTIONãå®è¡ããŸãã MAKE_FUNCTIONã¯æããã«é¢æ°ãäœæããŸããã¹ã¿ãã¯ã«CodeObjectãããããšãåæãšããŠããŸããäœããã®ã¢ã¯ã·ã§ã³ãå®è¡ããé¢æ°ãäœæããŠãé¢æ°ãã¹ã¿ãã¯ã«ããã·ã¥ããŸããããã§ããã¬ãŒã ã¹ã¿ãã¯ã«ãã£ãCodeObjectã®ä»£ããã«FUNCTIONãã§ããŸããããããŠããã®é¢æ°ãåç §ã§ããããã«ãto_powerå€æ°ã«é 眮ããå¿ èŠããããŸãã
Opcode STORE_NAMEãå®è¡ãããto_powerå€æ°ã«é 眮ãããŸããã¹ã¿ãã¯ã«é¢æ°ããããŸããããããã¯to_powerå€æ°ã§ãããåç §ã§ããŸãã
次ã«ã10 +ãã®é¢æ°ã®å€ãåºåããŸãã
Pythonã¯äœãããŸããïŒããã¯ãã€ãã³ãŒãã«å€æãããŸãããç§ãã¡ãæã£ãŠããæåã®opcodeã¯LOAD_CONSTã§ããããã10ãã¹ã¿ãã¯ã«ããŒãããŸããã¹ã¿ãã¯ã«12åç»å ŽããŸããã次ã«ãto_powerãå®è¡ããå¿ èŠããããŸãã
ãã®æ©èœã¯æ¬¡ã®ããã«å®è¡ãããŸããäœçœ®åŒæ°ãããå ŽåïŒæ®ãã¯ä»ã®ãšãã調ã¹ãŸããïŒãæåã®Pythonã¯é¢æ°èªäœãã¹ã¿ãã¯ã«é 眮ããŸãã次ã«ããã¹ãŠã®åŒæ°ãå ¥åããé¢æ°åŒæ°ã®åŒæ°çªå·ã䜿çšããŠCALL_FUNCTIONãåŒã³åºããŸãã
æåã®åŒæ°ãã¹ã¿ãã¯ã«ããŒãããŸãããããã¯é¢æ°ã§ãã
ããã«2ã€ã®åŒæ°ïŒ30ãš2ïŒãã¹ã¿ãã¯ã«ããŒãããŸãããããã§ãã¹ã¿ãã¯ã«é¢æ°ãš2ã€ã®åŒæ°ãã§ããŸãããã¹ã¿ãã¯ã®äžçªäžãäžçªäžã«ãããŸãã CALL_FUNCTIONãç§ãã¡ãåŸ ã£ãŠããŸãã CALL_FUNCTIONïŒ2ïŒãšèšããŸããã€ãŸãã2ã€ã®åŒæ°ãæã€é¢æ°ããããŸãã CALL_FUNCTIONã¯ãã¹ã¿ãã¯äžã«2ã€ã®åŒæ°ãããããã®åŸã«é¢æ°ãç¶ãããšãæ³å®ããŠããŸãã 2ã30ãããã³FUNCTIONããããŸãã
é²è¡äžã®Opcodeã
ãããã£ãŠãç§ãã¡ã«ãšã£ãŠã¯ããã®ã¹ã¿ãã¯ãé¢ãããšãæ°ããé¢æ°ãäœæãããããã§å®è¡ãè¡ãããŸãã
ãã¬ãŒã ã«ã¯ç¬èªã®ã¹ã¿ãã¯ããããŸãããã®æ©èœã®ããã«æ°ãããã¬ãŒã ãäœæãããŸãããããã¯ãŸã 空ã§ãã
ããã«å®è¡ãè¡ãããŸããããã§ã¯ãã§ã«ç°¡åã§ãã Aããã¯ãŒã¢ããããå¿ èŠããããŸããå€æ°A-30ã®å€ãã¹ã¿ãã¯ã«ããŒãããå€æ°power-2ã®å€ãããŒãããŸãã
ãããŠopcodeBINARY_POWERãå®è¡ãããŸãã
ããæ°å€ãå¥ã®æ°å€ã®çŽ¯ä¹ã«ããŠãã¹ã¿ãã¯ã«æ»ããŸããé¢æ°ã¹ã¿ãã¯ã§900ã«ãªããŸããã
次ã®opcodeRETURN_VALUEã¯ãã¹ã¿ãã¯ããåã®ãã¬ãŒã ã«å€ãè¿ããŸãã
ãããå®è¡ã®æ¹æ³ã§ããé¢æ°ãå®äºããŸãããåç §ããªããåã®é¢æ°ã®ãã¬ãŒã ã«2ã€ã®æ°åãããå Žåããã¬ãŒã ã¯ããããã¯ãªã¢ãããŸãã
ãã®åŸããã¹ãŠãã»ãŒåãã§ããè¿œå ãçºçããŸãã
ïŒ...ïŒåãšPyObjectã«ã€ããŠè©±ããŸãããã
ã¿ã€ãã³ã°
ãªããžã§ã¯ãã¯ã2ã€ã®äž»èŠãªãã£ãŒã«ããããsishæ§é ã§ããæåã®ãã£ãŒã«ãã¯ãã®ãªããžã§ã¯ããžã®åç §ã®æ°ã§ããã2çªç®ã¯ãªããžã§ã¯ãã®ã¿ã€ãã§ãããã¡ããããªããžã§ã¯ãã®ã¿ã€ããžã®åç §ã§ãã
ä»ã®ãªããžã§ã¯ãã¯ãPyObjectãå²ãããšã«ãã£ãŠç¶æ¿ããŸããã€ãŸããfloatãæµ®åå°æ°ç¹æ°ãPyFloatObjectãããæ§é ãèŠããšãPyObjectæ§é ã§ããHEADããããããã«ããã®floatèªäœã®å€ãæ ŒçŽãããŠããããŒã¿ïŒdouble ob_fvalïŒããããŸãã
ãããŠãããã¯ãªããžã§ã¯ãã®ã¿ã€ãã§ãã PyObjectã§åã確èªããŸãããããã¯ãåã瀺ãæ§é ã§ããå®éãããã¯ããã®ãªããžã§ã¯ãã®åäœãå®è£ ããé¢æ°ãžã®ãã€ã³ã¿ãŒãå«ãCæ§é ã§ããããŸããã€ãŸããããã«ã¯éåžžã«å€§ããªæ§é ããããŸããããšãã°ããã®ã¿ã€ãã®2ã€ã®ãªããžã§ã¯ããè¿œå ããå Žåã«åŒã³åºãããé¢æ°ãæå®ãããŠããŸãããŸãã¯ãæžç®ãããããã®ãªããžã§ã¯ããåŒã³åºãããäœæããŸããã¿ã€ãã§ã§ããããšã¯ãã¹ãŠããã®æ§é ã§æå®ããå¿ èŠããããŸãã
ããšãã°ãPythonã®intãintegersãèŠãŠã¿ãŸãããããŸããéåžžã«ç°¡ç¥åãããããŒãžã§ã³ãç§ãã¡ã¯äœã«èå³ãããã§ããããïŒ Intã«ã¯tp_nameããããŸãã tp_hashãããããšãããããŸããããã·ã¥intãååŸã§ããŸãã intã§hashãåŒã³åºããšããã®é¢æ°ãåŒã³åºãããŸãã tp_callãŒãããããå®çŸ©ãããŠããŸãããããã¯ãintãåŒã³åºããªãããšãæå³ããŸãã tp_str-æååãã£ã¹ããå®çŸ©ãããŠããŸããã Pythonã«ã¯ãæååã«ãã£ã¹ãã§ããstré¢æ°ããããŸãã
ã¹ã©ã€ãã«ã¯èŒã£ãŠããŸããããintãå°å·ã§ããããšã¯ãåç¥ã§ãããããªãããã§ãŒããªã®ã§ããïŒ tp_reprããããããPythonã«ã¯strãšreprã®2ã€ã®æåååãæž¡ãé¢æ°ããããŸããæååãžã®ãã詳现ãªãã£ã¹ããããã¯å®éã«å®çŸ©ãããŠãããã¹ã©ã€ãã«èŒã£ãŠããªãã£ãã ãã§ãå®éã«æååã«ã€ãªãããšåŒã³åºãããŸãã
æåŸã«ãtp_newïŒãã®ãªããžã§ã¯ãã®äœææã«åŒã³åºãããé¢æ°ïŒã衚瀺ãããŸãã tp_initã¯ãŒãã§ãã intã¯å¯å€åã§ã¯ãªããäžå€ã§ããããšã¯èª°ããç¥ã£ãŠããŸããäœæåŸã¯ãå€æŽããŠåæåããŠãæå³ããªãã®ã§ããŒãã«ãªããŸãã
ããšãã°ãBoolãèŠãŠã¿ãŸãããããåç¥ãããããŸããããPythonã®Boolã¯å®éã«ã¯intããç¶æ¿ããŠããŸããã€ãŸããBoolãè¿œå ããŠãäºãã«å ±æããããšãã§ããŸãããã¡ãããããã¯ã§ããŸããããå¯èœã§ãã
tp_baseïŒããŒã¹ãªããžã§ã¯ããžã®ãã€ã³ã¿ïŒãããããšãããããŸãããªãŒããŒã©ã€ããããã®ã¯ãtp_base以å€ã®ãã¹ãŠã§ããã€ãŸããç¬èªã®ååãç¬èªã®è¡šç€ºæ©èœããããæžã蟌ãŸããã®ã¯æ°åã§ã¯ãªããçãŸãã¯åœã§ããæ°å€ãšããŠã®è¡šçŸã§ã¯ãããã€ãã®è«çé¢æ°ãããã§ãªãŒããŒã©ã€ããããŸãã Docstringã¯ããèªèº«ãšãã®åµé ç©ã§ããä»ã®ãã¹ãŠã¯intããæ¥ãŠããŸãã
ãªã¹ãã«ã€ããŠç°¡åã«èª¬æããŸãã Pythonã§ã¯ããªã¹ãã¯åçé åã§ããåçé åã¯ã次ã®ããã«æ©èœããé åã§ããäºåã«ã¡ã¢ãªé åããã次å ã§åæåããŸããããã«èŠçŽ ãè¿œå ããŸããèŠçŽ ã®æ°ããã®ãµã€ãºãè¶ ãããšããã«ãäžå®ã®ããŒãžã³ã§ãã€ãŸã1ã€ã§ã¯ãªããè€æ°ã®å€ã§æ¡åŒµããã®ã§ãé©åãªç¹ããããŸãã
Pythonã§ã¯ããµã€ãºã¯0ã4ã8ã16ã25ã®ããã«å€§ãããªããŸããã€ãŸããå®æ°ã«å¯ŸããŠæŒžè¿çã«æ¿å ¥ãå®è¡ã§ããããçš®ã®åŒã«åŸããŸãããããŠããªã¹ãã«æ¿å ¥æ©èœããã®æç²ãããããšãããããŸããã€ãŸãããµã€ãºå€æŽãè¡ã£ãŠããŸãããµã€ãºå€æŽããªãå Žåã¯ããšã©ãŒãã¹ããŒããŠèŠçŽ ãå²ãåœãŠãŸããPythonã§ã¯ãããã¯Cã§å®è£ ãããéåžžã®åçé å
ã§ããïŒ...ïŒèŸæžã«ã€ããŠç°¡åã«èª¬æããŸãããããããã¯Pythonã®ããããšããã«ãããŸãã
èŸæž
ãªããžã§ã¯ãã§ã¯ãã¯ã©ã¹ã®æ§æå šäœãèŸæžã«å«ãŸããŠããããšã¯èª°ããç¥ã£ãŠããŸããå€ãã®ãã®ããããã«åºã¥ããŠããŸããããã·ã¥ããŒãã«å ã®Pythonã®èŸæžã
èŠããã«ãããã·ã¥ããŒãã«ã¯ã©ã®ããã«æ©èœããŸããïŒããã€ãã®éµããããŸãïŒãã£ããŒãããªãŒãã®ããããããèŸæžã«å ¥ãããã®ã§ãåããŒãããã·ã¥é¢æ°ã§å®è¡ããŸããããã·ã¥ã«ãªããŸãããã®ããã·ã¥ã䜿çšããŠãã±ãããæ€çŽ¢ããŸãããã±ããã¯ãèŠçŽ ã®é åå ã®åãªãæ°å€ã§ããæçµçãªã¢ãžã¥ãåå²ãçºçããŸãããã±ããã空ã®å Žåã¯ãç®çã®ã¢ã€ãã ããã±ããã«å ¥ããã ãã§ãã空ã§ã¯ãªãããã§ã«ããã€ãã®èŠçŽ ãååšããå Žåãããã¯è¡çªã§ããã次ã®ãã±ãããéžæããŠãããã空ããŠãããã©ããã確èªããŸãããããŠãç¡æã®ãã±ãããèŠã€ãããŸã§ç¶ããŸãã
ãããã£ãŠãè¿œå æäœãé©åãªæéå ã«å®è¡ããã«ã¯ãäžå®æ°ã®ãã±ãããåžžã«ç©ºããŠããå¿ èŠããããŸããããããªããšããã®é åã®ãµã€ãºã«è¿ã¥ããšãéåžžã«é·ãé空ããã±ãããæ€çŽ¢ãããã¹ãŠãé ããªããŸãã
ãããã£ãŠãPythonã§ã¯ãé åèŠçŽ ã®3åã®1ãåžžã«ããªãŒã§ããããšãçµéšçã«èªããããŠããŸãããããã®æ°ã3åã®2ãè¶ ããå Žåãé åã¯æ¡åŒµãããŸããèŠçŽ ã®3åã®1ãç¡é§ã«ãªããæçšãªãã®ãäœãä¿åãããªããããããã¯è¯ããããŸããã
ã¹ã©ã€ãããã®ãªã³ã¯
ãããã£ãŠãããŒãžã§ã³3.6以éãPythonã¯ãã®ãããªããšãè¡ã£ãŠããŸãããå·ŠåŽã«ã¯ã以åã®ç¶æ ã衚瀺ãããŸãããããã®3ã€ã®èŠçŽ ãæ ŒçŽãããŠããã¹ããŒã¹é åããããŸãã 3.6以éã圌ãã¯ãã®ãããªãŸã°ããªé åãéåžžã®é åã«ããããšã決å®ããŸããããåæã«ãã±ããèŠçŽ ã®ã€ã³ããã¯ã¹ãå¥ã®ã€ã³ããã¯ã¹é åã«æ ŒçŽããŸãã
ã€ã³ããã¯ã¹ã®é åãèŠããšãæåã®ãã±ããã«ã¯Noneãããã2çªç®ã®ãã±ããã«ã¯ãã®é åã®ã€ã³ããã¯ã¹1ã®èŠçŽ ããããŸãã
ããã«ãããæåã«ã¡ã¢ãªäœ¿çšéãåæžã§ãã次ã«ç¡æã§ç®±ããåºããŠããã«äœ¿çšã§ããŸããé åºä»ããããé åãã€ãŸããéåžžã®sish appendã䜿çšããŠãæ¡ä»¶ä»ãã§ãã®é åã«èŠçŽ ãè¿œå ãããšãé åã¯èªåçã«é åºä»ããããŸãã
Pythonã䜿çšããããã€ãã®èå³æ·±ãæé©åããããŸãããããã®ããã·ã¥ããŒãã«ãæ©èœãããã«ã¯ãèŠçŽ æ¯èŒæäœãå¿ èŠã§ããããã·ã¥ããŒãã«ã«èŠçŽ ãé 眮ããŠãããèŠçŽ ãååŸãããšããŸããããã·ã¥ãååŸãããã±ããã«ç§»åããŸããããããŸãïŒãã±ããããã£ã±ãã§ããããã«äœãããããŸããããããããã¯ç§ãã¡ãå¿ èŠãšããèŠçŽ ã§ããïŒé 眮ããããšãã«è¡çªãçºçããã¢ã€ãã ãå®éã«å¥ã®ãã±ããã«åãŸã£ãå¯èœæ§ããããŸãããããã£ãŠãããŒãæ¯èŒããå¿ èŠããããŸããããŒãééã£ãŠããå Žåã¯ãè¡çªè§£æ±ºã«äœ¿çšãããã®ãšåã次ã®ãã±ããæ€çŽ¢ã¡ã«ããºã ã䜿çšããŸãããããŠæ¬¡ã«é²ã¿ãŸãããã
ã¹ã©ã€ãããã®ãªã³ã¯
ãããã£ãŠãããŒæ¯èŒæ©èœãå¿ èŠã§ããäžè¬ã«ããªããžã§ã¯ããæ¯èŒããæ©èœã¯éåžžã«é«äŸ¡ã«ãªãå¯èœæ§ããããŸãããããã£ãŠããã®ãããªæé©åã䜿çšãããŸãããŸããã¢ã€ãã IDãæ¯èŒããŸãããåç¥ã®ããã«ãCPythonã®IDã¯ã¡ã¢ãªå ã®äœçœ®ã§ãã
IDãåãã§ããå Žåããããã¯åããªããžã§ã¯ãã§ããããã¡ããããããã¯åãã§ãã次ã«ãTrueãè¿ããŸããããã§ãªãå Žåã¯ãããã·ã¥ãèŠãŠãã ããããªãããã®æ¹æ³ã§åå®çŸ©ããŠããªãå Žåãããã·ã¥ã¯ããªãé«éãªæäœã«ãªãã¯ãã§ããããã2ã€ã®ãªããžã§ã¯ãããããã·ã¥ãååŸããŠæ¯èŒããŸãããããã®ããã·ã¥ãçãããªãå Žåããªããžã§ã¯ãã¯ééããªãçãããªããããFalseãè¿ããŸãã
ãããŠããããŸããªã±ãŒã¹ã§ã®ã¿-ããã·ã¥ãçãããããããåããªããžã§ã¯ãã§ãããã©ããããããªãå Žå-ãªããžã§ã¯ãèªäœãæ¯èŒããå Žåã®ã¿ã§ãã
èå³æ·±ãããšã«ãå埩äžã«ããŒã«äœãæ¿å ¥ããããšã¯ã§ããŸãããããã¯ééãã§ãã
å éšçã«ã¯ãèŸæžã«ã¯versionãšããå€æ°ããããèŸæžã®ããŒãžã§ã³ãæ ŒçŽããŸããèŸæžãå€æŽãããšãããŒãžã§ã³ãå€æŽãããPythonã¯ãããç解ããŠããšã©ãŒãã¹ããŒããŸãã
ããå®çšçãªäŸã§ã¯ãèŸæžã¯äœã«äœ¿çšã§ããŸããïŒã¿ã¯ã·ãŒã«ã¯æ³šæãããã泚æã®ã¹ããŒã¿ã¹ã¯å€æŽãããå¯èœæ§ããããŸããã¹ããŒã¿ã¹ãå€æŽãããšãã¯ãSMSã®éä¿¡ã泚æã®èšé²ãªã©ã®ç¹å®ã®ã¢ã¯ã·ã§ã³ãå®è¡ããå¿ èŠããããŸãã
ãã®ããžãã¯ã¯Pythonã§èšè¿°ãããŠããŸãã ã泚æç¶æ³ããããããã®ãªããããããããšãã圢ã®å·šå€§ãªifãæžããªãããã«ãããŒã泚æç¶æ³ã§ãããšããå£è¿°ããããŸãããŸããVALUEãžã®ã¿ãã«ãããããã®ã¹ããŒã¿ã¹ã«ç§»è¡ãããšãã«å®è¡ããå¿ èŠã®ãããã¹ãŠã®ãã³ãã©ãŒãå«ãŸããŠããŸããããã¯äžè¬çãªæ¹æ³ã§ãããå®éãã¹ã€ããã®ä»£ããã«ãªããŸãã
ã¿ã€ãå¥ã®ããã€ãã®äºæãäžå€ã«ã€ããŠã話ããŸãããããã¯äžå€ã®ããŒã¿ã¿ã€ãã§ãããå¯å€ã¯ããããå¯å€ã¿ã€ãã§ãïŒãã£ã¯ããŒã·ã§ã³ãã¯ã©ã¹ãã¯ã©ã¹ã€ã³ã¹ã¿ã³ã¹ãã·ãŒãããããŠå€åäœãä»ã®ãã®ãä»ã®ã»ãšãã©ãã¹ãŠã¯æååã§ãããæ°åã ãã§ã-ãããã¯äžå€ã§ããå¯å€ã¿ã€ããšã¯äœã§ããïŒãŸããã³ãŒããç解ããããããŸããã€ãŸããã³ãŒãã§äœããã¿ãã«ã§ããããšãããã£ãå Žåããã以äžå€æŽãããªãããšãç解ããŠããŸãããããã«ãããã³ãŒããèªã¿ããããªããŸãã次ã«äœãèµ·ããããç解ããŸãã tuple dsã§ã¯ãã¢ã€ãã ãå ¥åã§ããŸãããããªãã¯ãããç解ããã§ãããããããŠããã¯ããªããšããªãã®ããã«ã³ãŒããèªããã¹ãŠã®äººã ãèªãã®ãå©ããã§ãããã
ãããã£ãŠãã«ãŒã«ããããŸããäœããå€æŽããªãå Žåã¯ãäžå€ã®åã䜿çšããããšããå§ãããŸããããã¯ãŸãããéãä»äºã«ã€ãªãããŸãã tupleã䜿çšããå®æ°ã¯ãpit_tupleãtap_tupleãmaxãããã³CCã®2ã€ã§ãããã€ã³ãã¯äœã§ããïŒãµã€ãºã20ãŸã§ã®ãã¹ãŠã®ã¿ãã«ã«å¯ŸããŠãç¹å®ã®å²ãåœãŠæ¹æ³ã䜿çšãããŸããããã«ããããã®å²ãåœãŠãé«éã«ãªããŸãããããŠãããããã®ã¿ã€ãã®ãã®ãããªãªããžã§ã¯ãã¯ãæ倧ã§2,000åãŸã§ååšããå¯èœæ§ããããŸããããã¯ã·ãŒããããã¯ããã«é«éãªã®ã§ãã¿ãã«ã䜿çšãããšé«éã«ãªããŸãã
ã©ã³ã¿ã€ã ãã§ãã¯ããããŸããæããã«ãäœãããªããžã§ã¯ãã«æ¥ç¶ããããšããŠããŠãããããã®æ©èœããµããŒãããŠããªãå Žåã¯ããšã©ãŒãçºçããŸããããã¯ãäœãééã£ãããšããããšããäœããã®ç解ã§ãã dictã®ããŒã¯ãåç¶æéäžã«å€æŽãããªãããã·ã¥ãæã€ãªããžã§ã¯ãã®ã¿ã«ããããšãã§ããŸããäžå€ã®ãªããžã§ã¯ãã®ã¿ããã®å®çŸ©ãæºãããŸãããããã ããdictããŒã«ãªãããšãã§ããŸãã
Cã§ã¯ã©ã®ããã«èŠããŸããïŒäŸãå·ŠåŽã¯ã¿ãã«ãå³åŽã¯éåžžã®ãªã¹ãã§ãããã¡ãããããã§ã¯ãã¹ãŠã®éããèŠããããã§ã¯ãªããç§ãèŠãããã£ããã®ã ããèŠããŸãã tp_hashãã£ãŒã«ãã®ãªã¹ãã«ã¯NotImplementedããããŸããã€ãŸãããªã¹ãã«ã¯ããã·ã¥ããããŸãããã¿ãã«ã«ã¯ãå®éã«ããã·ã¥ãè¿ãé¢æ°ãããã€ããããŸãããããããšãããã¿ãã«ãdictããŒã«ãªãããšãã§ããlistãã§ããªãçç±ã§ãã
次ã«åŒ·èª¿è¡šç€ºãããã®ã¯ãã¢ã€ãã å²ãåœãŠé¢æ°sq_ass_itemã§ãããªã¹ãã§ã¯ãã¿ãã«ã§ã¯ãŒãã§ããã€ãŸããã¿ãã«ã«ã¯åœç¶äœãå²ãåœãŠãããšãã§ããŸããã
ããäžã€ã Pythonã¯ãèŠæ±ãããŸã§äœãã³ããŒããŸããããããèŠããŠããå¿ èŠããããŸããäœããã³ããŒãããå Žåã¯ãããšãã°ãcopy.deepcopyé¢æ°ãæã€copyã¢ãžã¥ãŒã«ã䜿çšããŸããéãã¯ãªãã§ããïŒ copyã¯ãå åŒãªã¹ããªã©ã®ã³ã³ãããªããžã§ã¯ãã®å Žåããªããžã§ã¯ããã³ããŒããŸãããã®ãªããžã§ã¯ãã«ãã£ããã¹ãŠã®åç §ã¯ãæ°ãããªããžã§ã¯ãã«æ¿å ¥ãããŸãããŸããdeepcopyã¯ããã®ã³ã³ãããŒå ããã³ãã以éã®ãã¹ãŠã®ãªããžã§ã¯ããååž°çã«ã³ããŒããŸãã
ãŸãã¯ããªã¹ãããã°ããã³ããŒããå Žåã¯ãåäžã®ã³ãã³ã¹ã©ã€ã¹ã䜿çšã§ããŸããããªãã¯ã³ããŒãæã«å ¥ããã§ãããããã®ãããªã·ã§ãŒãã«ããã¯ç°¡åã§ãã
ïŒ...ïŒæ¬¡ã«ãã¡ã¢ãªç®¡çã«ã€ããŠèª¬æããŸãã
ã¡ã¢ãªç®¡ç
sysã¢ãžã¥ãŒã«ãèŠãŠã¿ãŸããããã¡ã¢ãªã䜿çšããŠãããã©ããã確èªã§ããæ©èœããããŸããã€ã³ã¿ãŒããªã¿ãŒãèµ·åããŠã¡ã¢ãªå€æŽã®çµ±èšãèŠããšãå°ããªãªããžã§ã¯ããå«ãå€ãã®ãªããžã§ã¯ããäœæãããŠããããšãããããŸãããããŠããããã¯çŸåšäœæãããŠãããªããžã§ã¯ãã®ã¿ã§ãã
å®éãPythonã¯å®è¡æã«å€ãã®å°ããªãªããžã§ã¯ããäœæããŸãããŸããæšæºã®mallocé¢æ°ã䜿çšããŠããããå²ãåœãŠããšãã¡ã¢ãªãæçåãããŠãããããã¡ã¢ãªã®å²ãåœãŠãé ãããšã«ããã«æ°ä»ãã§ãããã
ããã¯ãç¬èªã®ã¡ã¢ãªãããŒãžã£ã䜿çšããå¿ èŠãããããšãæå³ããŸããèŠããã«ãããã¯ã©ã®ããã«æ©èœããŸããïŒ Pythonã¯ãã¢ãªãŒããšåŒã°ããã¡ã¢ãªã®ãããã¯ããããã256ãããã€ããã€å²ãåœãŠãŸããå éšã§ã¯ã圌ã¯èªåèªèº«ã4ãããã€ãã®ããŒã«ã«ã¹ã©ã€ã¹ããŸããããã¯ãã¡ã¢ãªããŒãžã®ãµã€ãºã§ããããŒã«å ã«ã¯ã16ã512ãã€ãã®ããŸããŸãªãµã€ãºã®ãããã¯ããããŸãã
512ãã€ãæªæºããªããžã§ã¯ãã«å²ãåœãŠãããšãããšãPythonã¯ç¬èªã®æ¹æ³ã§ãã®ãªããžã§ã¯ãã«é©ãããããã¯ãéžæãããã®ãªããžã§ã¯ãããã®ãããã¯ã«é 眮ããŸãã
ãªããžã§ã¯ãã®å²ãåœãŠã解é€ãããåé€ãããå Žåããã®ãããã¯ã¯ç©ºããšããŠããŒã¯ãããŸãããã ãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«ã¯æž¡ãããªãããã次ã®å Žæã§ãã®ãªããžã§ã¯ããåããããã¯ã«æžã蟌ãããšãã§ããŸããããã«ãããã¡ã¢ãªå²ãåœãŠãå€§å¹ ã«é«éåãããŸãã
ã¡ã¢ãªã解æŸããŸãã以åãPyObjectæ§é ãèŠãŸããã圌女ã¯ãã®refcnt-åç §ã«ãŠã³ããæã£ãŠããŸããããã¯éåžžã«ç°¡åã«æ©èœããŸãããã®ãªããžã§ã¯ããåç §ãããšãPythonã¯åç §ã«ãŠã³ããã€ã³ã¯ãªã¡ã³ãããŸãããªããžã§ã¯ããååŸãããšããã«ããã®ãªããžã§ã¯ããžã®åç §ãæ¶ããåç §ã«ãŠã³ãã®å²ãåœãŠã解é€ãããŸãã
é»è²ã§åŒ·èª¿è¡šç€ºãããŠãããã®ã refcntããŒãã§ãªãå Žåã¯ãããã§äœããè¡ã£ãŠããŸãã refcntããŒãã®å Žåãããã«ãªããžã§ã¯ãã®å²ãåœãŠã解é€ããŸããã¬ããŒãžã³ã¬ã¯ã¿ãŒãåŸ ã£ãŠããããã§ã¯ãããŸããããçŸæç¹ã§ã¡ã¢ãªãã¯ãªã¢ããŠããŸãã
delã¡ãœããã«åºããããå Žåãããã¯åã«å€æ°ã®ãªããžã§ã¯ããžã®ãã€ã³ããåé€ããŸãããŸããã¯ã©ã¹ã§å®çŸ©ã§ãã__del__ã¡ãœããã¯ããªããžã§ã¯ããå®éã«ã¡ã¢ãªããåé€ããããšãã«åŒã³åºãããŸãããªããžã§ã¯ãã«å¯ŸããŠdelãåŒã³åºããŸãããããã§ãåç §ãããå Žåããªããžã§ã¯ãã¯ã©ãã«ãåé€ãããŸããããããŠããã®ãã¡ã€ãã©ã€ã¶ãŒ__del__ã¯åŒã³åºãããŸããããããã¯éåžžã«äŒŒãŠãããšåŒã°ããŠããŸããã
ãªã³ã¯ã®æ°ã確èªããæ¹æ³ã«ã€ããŠã®çããã¢ã getrefcounté¢æ°ãæã€ãæ°ã«å ¥ãã®sysã¢ãžã¥ãŒã«ããããŸãããªããžã§ã¯ããžã®ãªã³ã¯ã®æ°ã確èªã§ããŸãã
ãã£ãšã話ãããŸãããªããžã§ã¯ããäœæãããŸãããªã³ã¯ã®æ°ã¯ããããååŸãããŸããèå³æ·±ã詳现ïŒå€æ°Aã¯TaxiOrderãæããŸãããªã³ã¯ã®æ°ãåããšãã2ããå°å·ãããŸãããªãã ãããïŒãªããžã§ã¯ãåç §ã1ã€ãããŸãããã ããgetrefcountãåŒã³åºããšããã®ãªããžã§ã¯ãã¯é¢æ°å ã®åŒæ°ã«å¯ŸããŠãã³ããŒãžãããŸãããããã£ãŠããã®ãªããžã§ã¯ããžã®åç §ã¯ãã§ã«2ã€ãããŸãã1ã€ç®ã¯å€æ°ã2ã€ç®ã¯é¢æ°åŒæ°ã§ãããããã£ãŠãã2ããåºåãããŸãã
æ®ãã¯äºçŽ°ãªããšã§ãããªããžã§ã¯ãã«å¥ã®å€æ°ãå²ãåœãŠããšã3ãåŸãããŸãã次ã«ããã®ãã€ã³ãã£ã³ã°ãåé€ãã2ãååŸããŸãã次ã«ããã®ãªããžã§ã¯ããžã®ãã¹ãŠã®åç §ãåé€ããåæã«ãã¡ã€ãã©ã€ã¶ãŒãåŒã³åºãããè¡ãåºåãããŸãã
ïŒ...ïŒCPythonã«ã¯ãæ§ç¯ã§ããªãèå³æ·±ãæ©èœããã1ã€ãããããã¥ã¡ã³ãã®ã©ãã«ãèšèŒãããŠããªãããã§ããæŽæ°ããã䜿çšãããŸããæ¯ååäœæããã®ã¯ãã£ãããªãã§ãããããããã£ãŠãæãäžè¬çã«äœ¿çšãããæ°å€ã§ããPythonéçºè ã¯ã-5ãã255ã®ç¯å²ãéžæããŸããããããã¯ã·ã³ã°ã«ãã³ã§ããã€ãŸãããããã¯äžåºŠäœæãããã€ã³ã¿ãŒããªã¿ãŒã®ã©ããã«ãããããããååŸããããšãããšãåããªããžã§ã¯ããžã®åç §ãååŸããŸããç§ãã¡ã¯AãšBãåããããããå°å·ãããããã®ã¢ãã¬ã¹ãæ¯èŒããŸãããçå®ã«ãªã£ãããããŠãããšãã°ããã®ãªããžã§ã¯ããžã®åç §ã105ãããŸããããã¯ãçŸåšãéåžžã«å€ãã®åç §ãããããã§ãã
ããšãã°1408ã®ããã«ãããã«å€§ããªæ°ããšããšããããã®ãªããžã§ã¯ãã¯çãããªãããããã2ã€ã®åç §ããããŸããå®éã1ã€ã
ã¡ã¢ãªã®å²ãåœãŠãšè§£æŸã«ã€ããŠå°ã話ããŸãããããã§ã¯ãã¬ããŒãžã³ã¬ã¯ã¿ãŒã«ã€ããŠè©±ããŸããããããã¯äœã®ããïŒããããã®ãªã³ã¯ãããããã§ãã誰ããªããžã§ã¯ããåç §ããªããªã£ããããããåé€ã§ããŸãããããã埪ç°ãªã³ã¯ãæã€ããšãã§ããŸããããšãã°ããªããžã§ã¯ãã¯ããèªäœãåç §ã§ããŸãããŸãã¯ãäŸã®ããã«ãããããããã€ããŒãåç §ãã2ã€ã®ãªããžã§ã¯ããååšããå ŽåããããŸããããã¯ãµã€ã¯ã«ãšåŒã°ããŸãããããŠããããã®ãªããžã§ã¯ããå¥ã®ãªããžã§ã¯ããžã®åç §ãäžããããšã¯ã§ããŸããããããåæã«ãããšãã°ãããã°ã©ã ã®å¥ã®éšåããã¯éæã§ããŸãããã¢ã¯ã»ã¹ã§ããã圹ã«ç«ããªããããåé€ããå¿ èŠããããŸããããªã³ã¯ããããŸããããã¯ãŸãã«ã¬ããŒãžã³ã¬ã¯ã¿ãŒã¢ãžã¥ãŒã«ã®ç®çã§ãããµã€ã¯ã«ãæ€åºãããããã®ãªããžã§ã¯ããåé€ããŸãã
圌ã¯ã©ã®ããã«åããŠããŸããïŒãŸããäžä»£ã«ã€ããŠç°¡åã«èª¬æãã次ã«ã¢ã«ãŽãªãºã ã«ã€ããŠèª¬æããŸãã
Pythonã§ã¬ããŒãžã³ã¬ã¯ã¿ãŒã®é床ãæé©åããããã«ãäžä»£å¥ã§ããã€ãŸããäžä»£ã䜿çšããŠæ©èœããŸãã 3äžä»£ãããŸãã圌ãã¯äœã®ããã«å¿ èŠã§ããïŒããæè¿äœæããããªããžã§ã¯ãã¯ã寿åœã®é·ããªããžã§ã¯ããããäžèŠã§ããå¯èœæ§ãé«ãããšã¯æããã§ããé¢æ°ã®éçšã§äœããäœæãããšããŸããã»ãšãã©ã®å Žåãé¢æ°ãçµäºãããšãã«å¿ èŠãããŸãããäžæå€æ°ã䜿çšããã«ãŒãã§ãåãã§ãããããã®ãªããžã§ã¯ãã¯ãã¹ãŠãé·ãéååšããŠãããªããžã§ã¯ããããé »ç¹ã«ã¯ãªãŒãã³ã°ããå¿ èŠããããŸãã
ãããã£ãŠããã¹ãŠã®æ°ãããªããžã§ã¯ãã¯ãŒãäžä»£ã«é 眮ãããŸãããã®äžä»£ã¯å®æçã«æž æãããŸãã Pythonã«ã¯3ã€ã®ãã©ã¡ãŒã¿ããããŸããåäžä»£ã«ã¯ç¬èªã®ãã©ã¡ãŒã¿ããããŸããããããååŸããã¬ããŒãžã³ã¬ã¯ã¿ãŒãã€ã³ããŒãããget_thresholdé¢æ°ãåŒã³åºããŠããããã®ãããå€ãååŸã§ããŸãã
ããã©ã«ãã§ã¯700ã10ã10ããããŸãã700ãšã¯äœã§ããïŒããã¯ããªããžã§ã¯ãã®äœææ°ããåé€æ°ãåŒããæ°ã§ãã 700ãè¶ ãããšããã«ãæ°äžä»£ã®ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãå§ãŸããŸãããŸãã10ã10ã¯åäžä»£ã®ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®æ°ã§ããããã®åŸãçŸåšã®äžä»£ã§ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãéå§ããå¿ èŠããããŸãã
ã€ãŸãããŒãäžä»£ã10åã¯ãªã¢ãããšã第1äžä»£ãããã«ããéå§ããŸãã第1äžä»£ã10åã¯ãªãŒãã³ã°ããåŸã第2äžä»£ã§ãã«ããéå§ããŸãããããã£ãŠããªããžã§ã¯ãã¯äžä»£ããäžä»£ãžãšç§»åããŸãã圌ããçãæ®ããªãã°ã圌ãã¯ç¬¬äžäžä»£ã«ç§»ããŸãã圌ãã第äžäžä»£ã®ãŽãåéãçãæ®ã£ãå Žåã圌ãã¯ç¬¬äºäžä»£ã«ç§»ãããŸãã第äºäžä»£ããã圌ãã¯ãã¯ãã©ãã«ã移åãããæ°žé ã«ããã«ãšã©ãŸããŸãã
ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã¯Pythonã§ã©ã®ããã«æ©èœããŸããïŒç¬¬0äžä»£ã§ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãéå§ãããšããŸããããã€ãã®ãªããžã§ã¯ããããããããã«ã¯ãµã€ã¯ã«ããããŸããå·ŠåŽã«ã¯çžäºã«åç §ãããªããžã§ã¯ãã®ã°ã«ãŒãããããå³åŽã®ã°ã«ãŒããçžäºã«åç §ããŠããŸããéèŠãªè©³çŽ°-ãããã¯ç¬¬1äžä»£ãããåç §ãããŸããPythonã¯ã©ã®ããã«ã«ãŒããæ€åºããŸããïŒãŸãããªããžã§ã¯ãããšã«äžæå€æ°ãäœæããããã®ãªããžã§ã¯ããžã®åç §æ°ãæžã蟌ãŸããŸããããã¯ã¹ã©ã€ãã«åæ ãããŠããŸããäžã®ãªããžã§ã¯ããžã®ãªã³ã¯ã2ã€ãããŸãããã ãã第1äžä»£ã®ãªããžã§ã¯ãã¯ãå€éšããåç §ãããŠããŸãã Pythonã¯ãããèŠããŠããŸãã次ã«ïŒéèŠã§ãïŒïŒäžä»£å ã®åãªããžã§ã¯ãã調ã¹ããã®äžä»£å ã®åç §ã®æ°ã ãã«ãŠã³ã¿ãŒãåé€ããã¯ãªã¡ã³ãããŸãã
ãããèµ·ãã£ãããšã§ããäžä»£å ã§çžäºã«åç §ããã ãã®ãªããžã§ã¯ãã®å Žåããã®å€æ°ã¯æ§é äžèªåçã«ãŒãã«ãªããŸããå€éšããåç §ããããªããžã§ã¯ãã®ã¿ã1ã€ã§ãã
Pythonã¯æ¬¡ã«äœãããŸããïŒåœŒã¯ãããã«1ã€ããã®ã§ããããã®ãªããžã§ã¯ããå€éšããåç §ãããŠããããšãç解ããŠããŸãããŸãããã®ãªããžã§ã¯ããŸãã¯ãã®ãªããžã§ã¯ãã®ãããããåé€ããããšã¯ã§ããŸãããããããªããšãç¡å¹ãªç¶æ³ãçºçããããã§ãããããã£ãŠãPythonã¯ãããã®ãªããžã§ã¯ãã第1äžä»£ã«è»¢éãã第0äžä»£ã«æ®ã£ãŠãããã®ã¯ãã¹ãŠåé€ããã¯ãªãŒã³ã¢ããããŸããã¬ããŒãžã³ã¬ã¯ã¿ãŒã«ã€ããŠã®ãã¹ãŠã
ïŒ...ïŒ é²ãããžã§ãã¬ãŒã¿ã«ã€ããŠç°¡åã«èª¬æããŸãã
ãžã§ãã¬ãŒã¿ãŒ
ããã§ã¯ãæ®å¿µãªãããžã§ãã¬ãŒã¿ãŒã®çŽ¹ä»ã¯ãããŸãããããžã§ãã¬ãŒã¿ãŒãšã¯äœãã説æããŠã¿ãŸããããããã¯ãæ¯èŒçèšãã°ãyieldãšããåèªã䜿çšããŠå®è¡ã®ã³ã³ããã¹ããèšæ¶ããäžçš®ã®é¢æ°ã§ãããã®æç¹ã§ãå€ãè¿ããã³ã³ããã¹ããèšæ¶ããŸãããã®åŸãããäžåºŠåç §ããŠããã®å€ãååŸã§ããŸãã
ãžã§ãã¬ãŒã¿ãŒã§äœãã§ããŸããïŒããªãã¯ãžã§ãã¬ãŒã¿ãŒãçã¿åºãããšãã§ããŸããããã¯ããªãã«å€ãè¿ããŸããæèãèŠããŠãããŠãã ããããžã§ãã¬ãŒã¿ãŒãè¿åŽã§ããŸãããã®å ŽåãStopIterationå®è¡ãã¹ããŒããããã®äžã«å€ïŒãã®å Žåã¯YïŒãå«ãŸããŸãã
ããŸãç¥ãããŠããªãäºå®ïŒããã€ãã®å€ããžã§ãã¬ãŒã¿ãŒã«éä¿¡ã§ããŸããã€ãŸãããžã§ãã¬ãŒã¿ãŒã§sendã¡ãœãããåŒã³åºããšãZïŒäŸãåç §ïŒããžã§ãã¬ãŒã¿ãŒãåŒã³åºãyieldåŒã®å€ã«ãªããŸãããžã§ãã¬ãŒã¿ãŒãå¶åŸ¡ãããå Žåã¯ãããã«å€ãæž¡ãããšãã§ããŸãã
ããã§äŸå€ãã¹ããŒããããšãã§ããŸããåãããšïŒãžã§ãã¬ãŒã¿ãªããžã§ã¯ããååŸããŠã¹ããŒããŸããããªãã¯ããã«ééããæããŸããæåŸã®æ©çãŸãã®ä»£ããã«ãšã©ãŒãçºçããŸãããããŠéãã-ãžã§ãã¬ãŒã¿ãéããããšãã§ããŸãã次ã«ãGeneratorExitã®å®è¡ãçºçãããžã§ãã¬ãŒã¿ã¯ä»ã«äœãçæããªãããšãæåŸ ãããŸãã
ããã§ã¯ãCPythonã§ã©ã®ããã«æ©èœãããã«ã€ããŠã話ãããããšæããŸããå®éã«ã¯ããžã§ãã¬ãŒã¿ãŒã«å®è¡ãã¬ãŒã ããããŸãããããŠèŠããŠããããã«ãFrameObjectã«ã¯ãã¹ãŠã®ã³ã³ããã¹ããå«ãŸããŠããŸãããã®ããšãããã³ã³ããã¹ããã©ã®ããã«ä¿æããããã¯æããã§ããã€ãŸãããžã§ãã¬ãŒã¿ãŒã«ãã¬ãŒã ãããã ãã§ãã
ãžã§ãã¬ãŒã¿ãŒé¢æ°ãå®è¡ãããšããPythonã¯ã©ã®ããã«ããŠãããå®è¡ããå¿ èŠããªãããšãèªèããŸããããžã§ãã¬ãŒã¿ãŒãäœæããŸããïŒèª¿ã¹ãCodeObjectã«ã¯ãã©ã°ããããŸãããŸããé¢æ°ãåŒã³åºããšãPythonã¯ãã®ãã©ã°ããã§ãã¯ããŸãã CO_GENERATORãã©ã°ãååšããå Žåãé¢æ°ãå®è¡ããå¿ èŠã¯ãªãããžã§ãã¬ãŒã¿ãŒãäœæããã ãã§ããããšãç解ããŸãããããŠåœŒã¯ãããäœæããŸãã PyGen_NewWithQualNameé¢æ°ã
å®è¡ã¯ã©ãã§ããïŒGENERATOR_FUNCTIONããããžã§ãã¬ãŒã¿ãŒã¯æåã«GENERATOR_ObjectãåŒã³åºããŸãã次ã«ãnextã䜿çšããŠGENERATOR_ObjectãåŒã³åºãã次ã®å€ãååŸã§ããŸãã次ã®åŒã³åºãã¯ã©ã®ããã«è¡ãããŸããïŒãã®ãã¬ãŒã ã¯ãžã§ãã¬ãŒã¿ãŒããååŸãããå€æ°Fã«æ ŒçŽãããEvalFrameExã€ã³ã¿ãŒããªã¿ãŒã®ã¡ã€ã³ã«ãŒãã«éä¿¡ãããŸããéåžžã®æ©èœãšåæ§ã«å®è¡ãããŸããYIELD_VALUEãããã³ãŒãã¯ããžã§ãã¬ãŒã¿ãŒã®å®è¡ãè¿ããäžæåæ¢ããããã«äœ¿çšãããŸãããã¬ãŒã å ã®ãã¹ãŠã®ã³ã³ããã¹ããèšæ¶ããå®è¡ãåæ¢ããŸããããã¯æåŸãã2çªç®ã®ãããã¯ã§ããã
ïŒ...ïŒäŸå€ãšã¯äœããããã³ããããPythonã§ã©ã®ããã«äœ¿çšãããããç°¡åã«èŠçŽããŸãã
äŸå€
äŸå€ã¯ããšã©ãŒç¶æ³ãåŠçããæ¹æ³ã§ãã tryãããã¯ããããŸããäŸå€ãã¹ããŒããå¯èœæ§ã®ãããã®ãè©ŠããŠã¿ãããšãã§ããŸããåèªraiseã䜿çšããŠãšã©ãŒãçºçãããããšãã§ãããšããŸãããããã ããç¹å®ã®çš®é¡ã®äŸå€ïŒãã®å Žåã¯SomeErrorïŒããã£ããã§ããŸãããã ããåŒãªãã§ãã¹ãŠã®äŸå€ããã£ããããŸãã elseãããã¯ã¯ããŸã䜿çšãããŸããããååšããäŸå€ãã¹ããŒãããªãã£ãå Žåã«ã®ã¿å®è¡ãããŸãããšã«ããfinallyãããã¯ãå®è¡ãããŸãã
CPythonã§äŸå€ã¯ã©ã®ããã«æ©èœããŸããïŒå®è¡ã¹ã¿ãã¯ã«å ããŠãåãã¬ãŒã ã«ã¯ãããã¯ã®ã¹ã¿ãã¯ããããŸããäŸã䜿çšããããšããå§ãããŸãã
ãããã¯ã¹ã¿ãã¯ã¯ããããã¯ãæžã蟌ãŸããã¹ã¿ãã¯ã§ããåãããã¯ã«ã¯ãã¿ã€ãããã³ãã©ãŒããã³ãã©ãŒããããŸãããã³ãã©ãŒã¯ããã®ãããã¯ãåŠçããããã«ãžã£ã³ããããã€ãã³ãŒãã¢ãã¬ã¹ã§ããããã¯ã©ã®ããã«æ©èœããŸããïŒã³ãŒãããããšããŸãããã tryãããã¯ãäœæããRuntimeErroräŸå€ããã£ããããexceptãããã¯ãšãfinallyãããã¯ãäœæããŸããã
ããã¯ãã¹ãŠãã®ãã€ãã³ãŒãã«çž®éããŸãã tryãããã¯ã®ãã€ãã³ãŒãã®æåã«ã40ãš12ã®åŒæ°ãæã€2ã€ã®2ã€ã®opcodeSETUP_FINALLYããããŸãããããã¯ãã³ãã©ãŒã®ã¢ãã¬ã¹ã§ãã SETUP_FINALLYãå®è¡ããããšããããã¯ããããã¯ã¹ã¿ãã¯ã«é 眮ãããŸããã€ãŸããç§ãåŠçããã«ã¯ãäžæ¹ã®å Žåã¯40çªç®ã®ã¢ãã¬ã¹ã«ãããäžæ¹ã®å Žåã¯12çªç®ã®ã¢ãã¬ã¹ã«ç§»åããŸãã
ã¹ã¿ãã¯ã®äžã®12ã¯ãelseRuntimeErrorãå«ãè¡ãé€ããŠã§ããããã¯ãäŸå€ãããå ŽåãSETUP_FINALLYã¿ã€ãã®ãããã¯ãæ€çŽ¢ããããã«ãããã¯ã¹ã¿ãã¯ã調ã¹ãããšãæå³ããŸããã¢ãã¬ã¹12ãžã®é·ç§»ããããããã¯ãèŠã€ããŠãããã«ç§»åããŸãããããŠãäŸå€ãšã¿ã€ãã®æ¯èŒããããŸããäŸå€ã®ã¿ã€ããRuntimeErrorã§ãããã©ããã確èªããŸããçããå Žåã¯å®è¡ããçãããªãå Žåã¯å¥ã®å Žæã«ãžã£ã³ãããŸãã
FINALLYã¯ããããã¯ã¹ã¿ãã¯ã®æ¬¡ã®ãããã¯ã§ããä»ã«äŸå€ãããå Žåã¯ãå®è¡ãããŸãã次ã«ããã®ãããã¯ã¹ã¿ãã¯ã§æ€çŽ¢ãç¶è¡ããã次ã®SETUP_FINALLYãããã¯ã«ç§»åããŸããããšãã°ãã¢ãã¬ã¹40ãéç¥ãããã³ãã©ãŒããããŸããã¢ãã¬ã¹40ã«ãžã£ã³ãããŸããã³ãŒãããããããfinallyãããã¯ã§ããããšãããããŸãã
CPythonã§ã¯éåžžã«ç°¡åã«æ©èœããŸããäŸå€ãçºçãããããšãã§ãããã¹ãŠã®é¢æ°ãå€ã³ãŒããè¿ããŸãããã¹ãŠåé¡ããªããã°0ãè¿ããããšã©ãŒã®å Žåã¯é¢æ°ã®çš®é¡ã«å¿ããŠ-1ãŸãã¯NULLãè¿ãããŸãã
Cã§ãã®ãããªæ¿å ¥å³ãåããŸããåå²ãã©ã®ããã«çºçãããã確èªããŸãããŸããBããŒãã«çããããŒãã§é€ç®ããããªãå Žåã¯ãäŸå€ãèšæ¶ããŠNULLãè¿ããšãããã§ãã¯ããããŸãããã®ããããšã©ãŒãçºçããŸããããããã£ãŠãåŒã³åºãã¹ã¿ãã¯ã®äžäœã«ããä»ã®ãã¹ãŠã®é¢æ°ãNULLãã¹ããŒããå¿ èŠããããŸããããã¯ã€ã³ã¿ãŒããªã¿ãŒã®ã¡ã€ã³ã«ãŒãã§ç¢ºèªããããã«ãžã£ã³ãããŸãã
ããã¯ã¹ã¿ãã¯ã®å·»ãæ»ãã§ãããã¹ãŠãç§ãèšã£ããšããã§ãããããã¯ã¹ã¿ãã¯å šäœã調ã¹ãŠããã®ã¿ã€ããSETUP_FINALLYã§ããããšã確èªããŸãããããããªããéåžžã«ç°¡åãªãã³ãã©ãŒãé£ã³è¶ããŸããå®éãããããã¹ãŠã§ãã
ãªã³ã¯
äžè¬çãªéèš³ïŒ
docs.python.org/3/reference/executionmodel.html
github.com/python/cpython
leanpub.com/insidethepythonvirtualmachine/read
ã¡ã¢ãªç®¡çïŒ
arctrix.com/nas/python/gc
rushter.com/blog/python -memory-managment
instagram-engineering.com/dismissing-python-garbage-collection-at-instagram-4dca40b29172
stackify.com/python-garbage-collection
äŸå€ïŒ
bugs.python.org/issue17611