Python线程挂了吗? [英] Python threading hanging?

查看:106
本文介绍了Python线程挂了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python程序,可以打开一个套接字并提取ssl证书.它工作得很好,但是当我在某个IP范围内运行它时,程序无法通过线程140.

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?

这是程序的线程部分

 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()

推荐答案

我不知道为什么它不起作用,但是我写了一个模块,您可以在文件开头将其导入:

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.

这篇关于Python线程挂了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆