PyMongo:当no_cursor_timeout = True时游标会发生什么 [英] PyMongo: What happens to cursor when no_cursor_timeout=True

查看:943
本文介绍了PyMongo:当no_cursor_timeout = True时游标会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看MongoDB的cursor文档,我看不到删除游标的方法.如果我在no_cursor_timeout属性设置为True的情况下使用游标,在PyMongo中会发生什么?即使我还没有到达游标结果的结尾,脚本终止时游标也会被删除吗?

Looking at the cursor docs for MongoDB, I don't see a way to delete a cursor. What happens in PyMongo if I am using a cursor with the no_cursor_timeout property set to True? Is the cursor deleted when my script terminates even if I have not gotten to the end of the cursor's results?

推荐答案

Python使用引用计数进行对象生存期管理,当Cursor对象超出范围时,垃圾收集器将调用__die(),后者将关闭光标. 如果要显式控制,则可以自己调用close().

Python uses reference counting for object lifetime management, when the Cursor object goes out of scope the garbage collector would call __die() which closes the cursor. If you want explicit control, you can call close() by yourself.

这篇关于PyMongo:当no_cursor_timeout = True时游标会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆