我正在尝试启动分离的QProcess并在其上完成一些事情。例如腻子隧道。我有课程来保存有关这两个过程的信息:
class TunnelInfo(object):
def __init__(self,tunnelprocess,mainprocess):
self.tp=tunnelprocess
self.mp=mainprocess
print "init"
self.mp.finished.connect(self.killTunnel)
def killTunnel(self,a,b):
print "killing tunnel"
print self.tp
self.tp.kill()
然后我正在尝试执行putty:
prcs=QtCore.QProcess(self.parent)
prcs.startDetached(self.conf.putty_path, ['-pw',d.password,'-l',d.login,d.ip])
ti=self.TunnelInfo(tp,prcs)
Putty开始没问题,但没有收到信号......我做错了什么?
答案 0 :(得分:0)
我发现某个地方startDetached是火灾而忘记。我用QThread解决了它:
class ConnectionThread(QtCore.QThread):
def __init__(self,parent,command,commandargs,tunnelthread=None):
super(ConnectionThread,self).__init__(parent.parent)
self.command=command
self.commandargs=commandargs
self.tunnelthread=tunnelthread
self.parent=parent
print command,commandargs
self.finished.connect(self.killtunnel)
def run(self):
self.process=QtCore.QProcess()
self.process.start(self.command,self.commandargs)
self.process.waitForFinished(msecs=3000000)
def killtunnel(self):
if self.tunnelthread is not None:
self.tunnelthread.process.kill()
self.tunnelthread.exit(0)
print "killed!"