我正在尝试观察一个过程并等待某种模式,比如:
open someFile id=123
然后,在那之后,我想等待
close id=123
我尝试编写脚本如下:
running_procs = [Popen(["process", "and", "options"], stdout=PIPE, stderr=PIPE)]
while running_procs:
    for proc in running_procs:
        retcode = proc.poll()
        if retcode is not None: # Process finished.
            running_procs.remove(proc)
            break
        else:
            while True:
                next_line = proc.stdout.readline()
                if next_line == '' and proc.poll() != None:
                    break
                m = re.search( r'someFile.*id\=([0-9]*)', next_line, re.M|re.I)
                if m:
                  print m.group(1)
但它似乎执行得太慢了。关于处理管道中的大量线路有什么建议吗?有更快的方法吗?