本文整理汇总了Python中PyQt5.QtCore.QSocketNotifier.deleteLater方法的典型用法代码示例。如果您正苦于以下问题:Python QSocketNotifier.deleteLater方法的具体用法?Python QSocketNotifier.deleteLater怎么用?Python QSocketNotifier.deleteLater使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QSocketNotifier
的用法示例。
在下文中一共展示了QSocketNotifier.deleteLater方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TwistedSocketNotifier
# 需要导入模块: from PyQt5.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt5.QtCore.QSocketNotifier import deleteLater [as 别名]
class TwistedSocketNotifier(QObject):
"""
Connection between an fd event and reader/writer callbacks.
"""
activated = pyqtSignal(int)
def __init__(self, parent, reactor, watcher, socketType):
QObject.__init__(self, parent)
self.reactor = reactor
self.watcher = watcher
fd = watcher.fileno()
self.notifier = QSocketNotifier(fd, socketType, parent)
self.notifier.setEnabled(True)
if socketType == QSocketNotifier.Read:
self.fn = self.read
else:
self.fn = self.write
self.notifier.activated.connect(self.fn)
def shutdown(self):
self.notifier.setEnabled(False)
self.notifier.activated.disconnect(self.fn)
self.fn = self.watcher = None
self.notifier.deleteLater()
self.deleteLater()
def read(self, fd):
if not self.watcher:
return
w = self.watcher
# doRead can cause self.shutdown to be called so keep
# a reference to self.watcher
def _read():
#Don't call me again, until the data has been read
self.notifier.setEnabled(False)
why = None
try:
why = w.doRead()
inRead = True
except:
inRead = False
log.err()
why = sys.exc_info()[1]
if why:
self.reactor._disconnectSelectable(w, why, inRead)
elif self.watcher:
self.notifier.setEnabled(True)
# Re enable notification following sucessfull read
self.reactor._iterate(fromqt=True)
log.callWithLogger(w, _read)
def write(self, sock):
if not self.watcher:
return
w = self.watcher
def _write():
why = None
self.notifier.setEnabled(False)
try:
why = w.doWrite()
except:
log.err()
why = sys.exc_info()[1]
if why:
self.reactor._disconnectSelectable(w, why, False)
elif self.watcher:
self.notifier.setEnabled(True)
self.reactor._iterate(fromqt=True)
log.callWithLogger(w, _write)