Python多处理,python代码在使用多进程时挂起

时间:2017-05-24 09:24:48

标签: python multiprocessing

下面是调用paramiko_ssh_machine并执行linux命令的测试用例。 没有多处理代码工作,但只要我启用多处理,python就会挂起并发现崩溃。

global file_handle
import os , sys
import paramiko_ssh_linux
import logging_path 
import CFG
import multiprocessing

from datetime import datetime


file_handle= logging_path.log_result(sys.argv[0])
print "Output value returned ", file_handle
file_handle.write('My name is prince\n')


host='10.12.29.118'
host2='10.12.29.116'



##xecute the first command on the remote linux machine
cmd='uname -a'
cmd2="ifconfig -a"
list_cmd=[cmd , cmd2]

now=datetime.now()
print "STARTING TIME: " , now


for x in range(5):


    process1=multiprocessing.Process(target=paramiko_ssh_linux.ssh_remote_machine,args=((file_handle,host,list_cmd),))

    process2=multiprocessing.Process(target=paramiko_ssh_linux.ssh_remote_machine, args=((file_handle,host2,list_cmd),))
    process1.start()
    process2.start()

    process1.join()
    process2.join()


now=datetime.now()
print "ENDING TIME", now

#End the logging of the test case
logging_path.end_logging(file_handle)

0 个答案:

没有答案