多线程处理-较早完成的处理结果

时间:2018-09-22 11:54:11

标签: python multithreading output-buffering

我是这里的新手,我正在尝试使一个小过程自动化。 我正在尝试制作一个使用whois查找和nikto检查域的工具,我正在使用多处理程序,但是两者都同时打印结果。有没有办法使两个进程并行运行,但是已终止的进程先打印其结果,然后再打印另一个进程。我的意思是,直到whoislookup不会终止之前,nikto都会在后台运行,但不会打印任何内容。

代码如下:

#!/usr/bin/env python3
import threading
import os 
hi=input("Hello! Please input the URL\n")
def whois():
    neat = hi.replace("https://www.", "")
    print(neat)
    final = 'whois ' + neat
    print(final)
    os.system(final)

def nikto():
    neat = hi.replace("https://", "")
    comm = 'nikto -h ' + neat
    os.system(comm)

if __name__ == "__main__":
    threading.Thread(target = whois).start()
    threading.Thread(target = nikto).start()

感谢您的帮助!

编辑:我知道这与禁用输出缓冲区有关,但我不知道如何处理?

0 个答案:

没有答案