0

我正在尝试启动分离的 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()

然后我正在尝试执行腻子:

prcs=QtCore.QProcess(self.parent)
prcs.startDetached(self.conf.putty_path, ['-pw',d.password,'-l',d.login,d.ip])
ti=self.TunnelInfo(tp,prcs)

腻子启动正常,但没有收到信号......我做错了什么?

4

1 回答 1

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!"
于 2013-04-10T11:52:57.187 回答