在 Twisted Python 中 - 确保协议实例被完全释放
我有一个用 Twisted Python 编写的相当密集的聊天套接字服务器,我使用带有工厂的 internet.TCPServer 启动它,该工厂引用了处理与客户端的所有通信的协议对象。
一旦客户端断开连接,我应该如何确保协议实例完全销毁自身?
我有一个名为 connectionLost 的函数,一旦客户端断开连接,该函数就会启动,并且我尝试停止那里的所有活动,但我怀疑一些反应器内容(如twisted.words 实例)仍在为过时的协议实例运行。
处理这个问题的最佳方法是什么?
谢谢!
I have a pretty intensive chat socket server written in Twisted Python, I start it using internet.TCPServer with a factory and that factory references to a protocol object that handles all communications with the client.
How should I make sure a protocol instance completely destroys itself once a client has disconnected?
I've got a function named connectionLost that is fired up once a client disconnects and I try stopping all activity right there but I suspect some reactor stuff (like twisted.words instances) keep running for obsolete protocol instances.
What would be the best approach to handle this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,为了解决这个问题,我在协议类中设置了一个 __del__ 方法,现在我正在记录客户端断开连接后 1 分钟内尚未进行垃圾收集的协议实例。
如果有人有更好的解决方案,我仍然会很高兴听到它,但到目前为止我已经使用此日志修复了一些潜在的内存泄漏。
谢谢!
ok, for sorting out this issue I have set a
__del__
method in the protocol class and I am now logging protocol instances that have not been garbage collected within 1 minute from the time the client has disconnected.If anybody has any better solution I'll still be glad to hear about it but so far I have already fixed a few potential memory leaks using this log.
Thanks!