Python线程悬挂?

时间:2014-07-23 19:14:43

标签: python multithreading sockets ssl

我有一个python程序,它打开一个套接字并提取ssl证书。它工作得很好但是当我在某个IP范围内运行它时,程序不会继续通过线程140.有没有办法看看它为什么不继续?

这是程序的线程部分

 createdThreads = 0
    threadSplit = len(self.IP_list) / 5

        #Splitting the work up between the threads
    thread_1_list = self.IP_list[0:threadSplit]
    thread_2_list = self.IP_list[threadSplit:(threadSplit*2)]
    thread_3_list = self.IP_list[(threadSplit*2):(threadSplit*3)]
    thread_4_list = self.IP_list[(threadSplit*3):(threadSplit*4)]
    thread_5_list = self.IP_list[(threadSplit*4):(threadSplit*5)]`
    thread_6_list = self.IP_list[(threadSplit*5):]

    threadList = [] 
    for address in range(threadSplit):
        thread_1 = getCertInfo(thread_1_list[address],self)
        thread_2 = getCertInfo(thread_2_list[address],self)
        thread_3 = getCertInfo(thread_3_list[address],self)
        thread_4 = getCertInfo(thread_4_list[address],self)
        thread_5 = getCertInfo(thread_5_list[address],self)
        thread_1.start()
        thread_2.start()
        thread_3.start()
        thread_4.start()
        thread_5.start()

        thread_1.join()      
        thread_2.join()
        thread_3.join()
        thread_4.join()
        thread_5.join()

        if address == threadSplit-1:
            for address in range(len(thread_6_list)):
                thread_6 = getCertInfo(thread_6_list[address],self)
                thread_6.start()
                thread_6.join()

1 个答案:

答案 0 :(得分:4)

我不知道为什么它不起作用,但我写了一个module,你可以在文件的开头导入:

import hanging_threads # https://gist.github.com/niccokunzmann/6038331

它将显示线程挂起的位置,您可以进一步调试。