首页 > 编程语言 > 详细

__del__ PyPy和CPython的不同点 动态编译(注意不是解释) 析构函数被调用的次数

时间:2020-03-03 10:50:32      阅读:59      评论:0      收藏:0      [点我收藏+]

小结

1、cpy的垃圾回收会对调用__del__多次;pypy仅仅一次;

 

https://www.liaoxuefeng.com/wiki/1016959663602400/1016966024263840

PyPy是另一个Python解释器,它的目标是执行速度。PyPy采用JIT技术,对Python代码进行动态编译(注意不是解释),所以可以显著提高Python代码的执行速度。

绝大部分Python代码都可以在PyPy下运行,但是PyPy和CPython有一些是不同的,这就导致相同的Python代码在两种解释器下执行可能会有不同的结果。如果你的代码要放到PyPy下执行,就需要了解PyPy和CPython的不同点

https://pypy.readthedocs.io/en/latest/cpython_differences.html

 

There are a few extra implications from the difference in the GC. Most notably, if an object has a __del__, the __del__ is never called more than once in PyPy; but CPython will call the same __del__ several times if the object is resurrected and dies again (at least it is reliably so in older CPythons; newer CPythons try to call destructors not more than once, but there are counter-examples). The __del__ methods are called in “the right” order if they are on objects pointing to each other, as in CPython, but unlike CPython, if there is a dead cycle of objects referencing each other, their __del__ methods are called anyway; CPython would instead put them into the list garbage of the gc module. More information is available on the blog [1] [2].

 

__del__ PyPy和CPython的不同点 动态编译(注意不是解释) 析构函数被调用的次数

原文:https://www.cnblogs.com/yuanjiangw/p/12400463.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!