创新互联Python教程:弱引用对象

弱引用对象

python 支持 “弱引用” 作为一类对象。具体来说,有两种直接实现弱引用的对象。第一种就是简单的引用对象,第二种尽可能地作用为一个原对象的代理。

创新互联主营晋中网站建设的网络公司,主营网站建设方案,重庆APP开发,晋中h5成都微信小程序搭建,晋中网站营销推广欢迎晋中等地区企业咨询

int PyWeakref_Check(ob)

如果 ob 是一个引用或代理对象则返回真值。 此函数总是会成功执行。

int PyWeakref_CheckRef(ob)

如果 ob 是一个引用对象则返回真值。 此函数总是会成功执行。

int PyWeakref_CheckProxy(ob)

如果 ob 是一个代理对象则返回真值。 此函数总是会成功执行。

PyObject *PyWeakref_NewRef(PyObject *ob, PyObject *callback)

Return value: New reference. Part of the Stable ABI.

Return a weak reference object for the object ob. This will always return a new reference, but is not guaranteed to create a new object; an existing reference object may be returned. The second parameter, callback, can be a callable object that receives notification when ob is garbage collected; it should accept a single parameter, which will be the weak reference object itself. callback may also be None or NULL. If ob is not a weakly referencable object, or if callback is not callable, None, or NULL, this will return NULL and raise TypeError.

PyObject *PyWeakref_NewProxy(PyObject *ob, PyObject *callback)

Return value: New reference. Part of the Stable ABI.

Return a weak reference proxy object for the object ob. This will always return a new reference, but is not guaranteed to create a new object; an existing proxy object may be returned. The second parameter, callback, can be a callable object that receives notification when ob is garbage collected; it should accept a single parameter, which will be the weak reference object itself. callback may also be None or NULL. If ob is not a weakly referencable object, or if callback is not callable, None, or NULL, this will return NULL and raise TypeError.

PyObject *PyWeakref_GetObject(PyObject *ref)

Return value: Borrowed reference. Part of the Stable ABI.

返回弱引用对象 ref 的被引用对象。如果被引用对象不再存在,则返回 Py_None

备注

该函数返回被引用对象的一个 borrowed reference。 这意味着应该总是在该对象上调用 Py_INCREF(),除非是当它在借入引用的最后一次被使用之前无法被销毁的时候。

PyObject *PyWeakref_GET_OBJECT(PyObject *ref)

Return value: Borrowed reference.

Similar to PyWeakref_GetObject(), but does no error checking.

新闻名称:创新互联Python教程:弱引用对象
分享网址:http://www.shufengxianlan.com/qtweb/news12/111112.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联