Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
线程内循环中的Python Subprocess.Popen_Python_Multithreading_Subprocess_Popen - Fatal编程技术网

线程内循环中的Python Subprocess.Popen

线程内循环中的Python Subprocess.Popen,python,multithreading,subprocess,popen,Python,Multithreading,Subprocess,Popen,我正在尝试使用python 2.7.5创建自己的应用程序,以帮助我诊断服务器。应用程序在for循环中使用subprocess.Popen 代码示例: from subprocess import Popen, PIPE def date_time_fnc(): for server in server_names: date_time = "ssh {} '. ~/.profile;/bin/date'".format(server)

我正在尝试使用python 2.7.5创建自己的应用程序,以帮助我诊断服务器。应用程序在for循环中使用subprocess.Popen

代码示例:

from subprocess import Popen, PIPE

def date_time_fnc():

     for server in server_names:
          date_time = "ssh {} '. ~/.profile;/bin/date'".format(server) 
          date_time_hf = Popen(date_time , shell=True, stdout=PIPE, stderr=PIPE)
          date_time_out = date_time_hf.communicate()
我使用另外5个函数和for循环以及其他命令。 应用程序正在运行,但它经常卡在其中一个循环中

我也使用Tkinter和线程。 因此,执行诊断的功能按以下方式运行:

def start():
    t = threading.Thread(target=check_system)
    t.setDaemon(True)
    t.start()
在函数内部,我调用其他函数:

    t1 = threading.Thread(target=date_time_fnc)
    t1.start()

    t2 = threading.Thread(target=spv_sh_me_v)
    t2.start()

    t3 = threading.Thread(target=core_dump_check)
    t3.start()

    t4 = threading.Thread(target=softbus_overflow)
    t4.start()

    t5 = threading.Thread(target=hdd_space)
    t5.start()

    t6 = threading.Thread(target=ui)
    t6.start()


    t1.join()
    t2.join()
    t3.join()
    t4.join()
    t5.join()
    t6.join()


有人知道如何处理随机应用程序挂起吗?

为什么您使用的是Python 2.7而不是最新版本的Python 3?因为每个线程都试图建立网络连接,所以这段时间可能会出现一些问题。比方说,可能服务器不允许提供身份验证方法(例如,您提供密码,它需要pub_密钥)。你应该在这里和那里添加一些
print
语句,添加异常处理(如果没有)。处理随机应用程序挂起的想法是使用调试技术来确定原因,然后消除原因或解决问题。我尝试在没有线程的情况下逐步执行这些功能。问题是一样的。我在我使用popen的行前后添加了print。注意:我必须使用旧版本的python,因为应用程序将部署在旧系统上,不允许使用任何更新的东西