Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

multithreading - Python threading hanging?

I have a python program that opens a socket and pulls the ssl cert. It works great but when I run it against a certain IP range the program does not proceed past thread 140. Is there a way to see why its not proceeding?

This is the threading portion of the program

 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()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I do not know why it is not working but I wrote a module that you can import at the beginning of the file:

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

It will show you where the threads hang and you can debug further.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...