开发者社区> 问答> 正文

这段代码python怎么解释:报错

import threading
import time
class downloadMutiThread(threading.Thread):
    def run(self):
        print threading.activeCount()
        print threading.enumerate() 
        time.sleep(1)
        downloadMutiThread().start()



downloadMutiThread().start()
这个是我自己写的一个线程测试模块  请问这样写 有什么问题吗? 我不是很理解   随着sleep时间的变长 alive的线程会变多些 如果这样写  怎么控制同时存在的线程数量?

展开
收起
kun坤 2020-06-09 11:52:20 442 0
1 条回答
写回答
取消 提交回答
  • import threading import time class downloadMutiThread(threading.Thread):     def run(self):         print threading.activeCount()         print threading.enumerate()          time.sleep(2)         if threading.activeCount()>2:             pass         else:             downloadMutiThread().start() downloadMutiThread().start()

    现在写成这样  这个算不算作一个粗糙的线程池。。。 ######这个代码会陷入死循环吗?######刚刚运行的时候 不会 现在运行 跑不起来了。。。。

    2020-06-09 11:52:26
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载