2

我有一个启动的进程,subprocess.Popen()它意味着无限期地运行。我遇到的问题是该过程似乎在大约 20 秒后停止运行。果然,当我检查时top,它表明该进程正在进入睡眠状态。当我手动运行命令时,这不会发生。

有谁知道我怎样才能阻止这种情况发生?

这是子流程调用:

aireplay = subprocess.Popen('aireplay-ng -3 -b ' + target.mac + ' ' + interface, 
                            shell=True, stdout = subprocess.PIPE, stderr = DN)

time.sleep(5)
starttime = time.time()
ivs = 0
second = False
print 'Sending deauth to generate arps...'
send_deauth(target)

while time.time() - starttime < 1200:
    targets = parsecsvfile('crackattempt')
    print 'Captured ' + str(ivs) + ' ivs.'
    print aireplay.poll()
    if len(targets[0]) > 0:
        target = targets[0][0]
        if ivs > 20000:
            break
        else :
            ivs = int(target.ivs)

    time.sleep(1)
4

1 回答 1

7

您正在管道传输子流程的输出。当它的缓冲区已满时它会休眠 - 你记得从子进程中读取标准输出吗?

communicate如果您不介意它阻塞,或者从文件描述符中读取,或者可能将标准输出发送到 /dev/null,您可以使用该方法stdout,因为您似乎没有使用它。

于 2012-06-07T23:21:02.923 回答