在 Twisted Python 中 - 确保协议实例被完全释放

发布于 2024-07-30 09:54:35 字数 292 浏览 3 评论 0原文

我有一个用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

靖瑶 2024-08-06 09:54:35

好的,为了解决这个问题,我在协议类中设置了一个 __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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文