【发布时间】:2014-07-23 18:02:43
【问题描述】:
在 Windows 和 Unix 上使用 Python 3.4,我的意思是使用 QSocketNotifier 来发现管道已准备好读取。这是一种人为的例子,因为管道是在单个进程中使用的。无论哪种方式,问题的关键在于,当管道上有要阅读的内容时,我需要采取行动。
我想出了下面的演示程序,但是 QSocketNotifier 从不发出它的activated 信号。我错过了什么明显的东西吗?
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import os
def can_read(fd):
print('File {} can be read'.format(fd))
def start():
print('Starting')
reader, writer = os.pipe()
notifier = QSocketNotifier(reader, QSocketNotifier.Read, w)
notifier.setEnabled(True)
notifier.activated.connect(can_read)
os.write(writer, b'a')
os.close(writer)
app = QApplication([])
QTimer.singleShot(0, start)
w = QMainWindow()
w.show()
app.exec_()
【问题讨论】:
-
你在管道上写过什么吗?
-
@mdurant 在 start() 中有
os.write调用。
标签: python windows qt unix pyqt