我有一个调用可执行文件的 pyside 应用程序。我想在 n 个进程中异步运行这个可执行文件,并在 QTextEdit 中捕获每个进程的输出。
目前我有:
def run(self, args, worklist):
self.viewer = OutputDialog(self)
self.procs = []
for path in worklist:
final_args = args + path
p = QtCore.QProcess(self)
p.readyReadStandardOutput.connect(self.write_process_output)
self.procs.append(p)
p.start(self.exe, final_args)
def write_process_output(self):
for p in self.procs:
self.viewer.text_edit.append(p.readAllStandardOutput())
这太笨重了,因为每次进程发送“就绪”信号时,它都会尝试获取所有进程的输出。
如何获取发送信号的进程的输出?
使用连接信号lambda
这样相关的进程就会被传递到槽中:
p.readyReadStandardOutput.connect(
lambda process=p: self.write_process_output(process))
def write_process_output(self, process):
self.viewer.text_edit.append(process.readAllStandardOutput())
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)