回溯错误后,子进程Popen不会终止:

时间:2016-03-17 01:27:54

标签: python

在我的python脚本中,我向目标机器发出“连接命令”。每个脚本结束我发出“断开命令”。只要没有引发错误,脚本就可以通过子进程(连接和断开连接)正常工作。

我在这里遇到的问题,如下面的情况所示,其中Key Value错误被引发,即使我已经给出了“除了”它不会做任何事情,我的进程也会挂起。我想因为脚本启动了一个Connect命令 它仍然坚持下去。我不知道如何强制杀死下面的Popen进程。请帮忙 !!!。我正在使用Python25

try:# I am creating subprocess to run my python scripts  
    retcode = subprocess.Popen(shlex.split('python '' ' + "'%s'"%      (PythonTestScript) + ' ' ), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    #is done for parallel printing to Console and a file that works just fine
    while True:  
          output = retcode.stdout.readline()
          if output == ''and retcode.poll() is not None:
             break
          if output:
             print output.strip()
             outputfile.write(output)
except OSError, e:
      print >>sys.stderr, "Execution failed:", e
      returnvalue = os.popen('TASKKILL /PID '+str(retcode.pid)+' /F')

追踪(最近一次通话): 文件“PythonTestScript”,第27行,in LocalDict( '姓名', '年龄', '日期') KeyError :('姓名','年龄','日期')

0 个答案:

没有答案