修复 InfluxDBClient 的 __del__ 错误抑制 DirectComposition 警告
parent
3b644a3acb
commit
a0417d080c
|
|
@ -115,17 +115,32 @@ class InfluxDBClient(QObject):
|
|||
@Slot()
|
||||
def disconnect(self):
|
||||
"""断开连接"""
|
||||
# 安全地停止定时器(可能在程序退出时已被销毁)
|
||||
if self._timer:
|
||||
self._timer.stop()
|
||||
try:
|
||||
self._timer.stop()
|
||||
except RuntimeError:
|
||||
# QTimer 已被销毁,忽略错误
|
||||
pass
|
||||
self._timer = None
|
||||
|
||||
if self._client:
|
||||
self._client.close()
|
||||
try:
|
||||
self._client.close()
|
||||
except Exception:
|
||||
# 客户端可能已被关闭,忽略错误
|
||||
pass
|
||||
self._client = None
|
||||
|
||||
self._is_connected = False
|
||||
|
||||
def __del__(self):
|
||||
self.disconnect()
|
||||
"""析构函数:安全地清理资源"""
|
||||
try:
|
||||
self.disconnect()
|
||||
except Exception:
|
||||
# 程序退出时 Qt 对象可能已被销毁,忽略所有异常
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue