【问题标题】:Python Gtk2 & Vte wait for the process Pid is finishPython Gtk2 & Vte 等待进程 Pid 完成
【发布时间】:2014-05-10 13:34:24
【问题描述】:

我在 GTK 窗口中使用 VTE 模块来运行并显示 bash 脚本的结果。

      adresse = self.champ.get_text()    
      pid = self.v.fork_command(None, ['/bin/bash', "./pluzz.sh", adresse])

      if pid == None:         #pseudocode
          print "Finish"

如果有 time.sleep 或循环,子进程将阻塞(不运行)。 我能怎么做 ?谢谢

编辑: 试过这个:

def check_pid(pid):        
    """ Check For the existence of a unix pid. """
    try:
        os.kill(pid, 0)
    except OSError:
        return False
    else:
        return True

问题是返回一次为真,如果我写一个循环,bash 脚本就会阻塞。

【问题讨论】:

  • 当您在 if 语句中检查 pid 时会发生什么。抱歉,我真的不知道这个工具包,只是想帮助...
  • 我已经编辑了我的问题,但我不知道这是否是好方法。 Vte 在 Gtk 窗口中 fork 一个终端,与 Xterm 类似,但已集成
  • 我在这里读过stackoverflow.com/questions/10684180/…,但我不知道是不是一样。我不明白代码..
  • 也许:docs.python.org/2/library/os.html#os.waitpid 抱歉,我帮不上什么忙
  • 好的,谢谢,我会看的。

标签: python gtk fork vte


【解决方案1】:

我找到了解决办法:

def __init__(self):
   a=0
   self.fenetre = gtk.Window(gtk.WINDOW_TOPLEVEL)
   [...]
   self.v = vte.Terminal()
#  self.v.connect ("child-exited", lambda term: gtk.main_quit())  # this is the line to change
   self.v.connect ("child-exited", lambda term: self.copie(self, a)) # the redirection after the process is finish
   self.v.show()

def download(self, a, donnees=None): 
   child_pid = self.v.fork_command(None, ['/bin/bash', "./pluzz.sh", adresse])

def copie(self, a, donnees=None):        
              print "FINISH"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-27
    • 2022-01-23
    • 2010-11-06
    • 2011-11-09
    • 2012-07-27
    相关资源
    最近更新 更多