python--线程active_count

源码: tests/active_count.py

import time
import unittest
import threading


class TestActiveCount(unittest.TestCase):

    def test_thread_number(self):

        def other_thread():
            time.sleep(10)

        number = 5
        ts = [threading.Thread(target=other_thread, args=())
              for i in range(number)]
        [t.start() for t in ts]
        self.assertEqual(threading.active_count(), number+1)
        time.sleep(15)
        self.assertEqual(threading.active_count(), 1)
        [t.join() for t in ts]

 
 

测试: tests/main.py

import unittest


TEST_MODULE = [
    "ln_threading.tests.active_count"
]


if __name__ == '__main__':
    suite = unittest.defaultTestLoader.loadTestsFromNames(TEST_MODULE)
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(suite)

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,077评论 19 139
  • 接口测试自动化的优点: 1,web自动化说起来很多人都会直接想到UI自动化这个设计,很少有人直接第一个概念是接口自...
    路边看雪的小男孩阅读 10,367评论 1 26
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,142评论 6 342
  • Python 面向对象Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对...
    顺毛阅读 9,703评论 4 16
  • 红尘深千丈,繁华镜水月。哦,那是谁的心灵,在滚滚喧嚣里,无处安放。 如果,你遇到一个写诗的女子,有没有觉得,你其实...
    溪流娟娟阅读 1,216评论 1 7

友情链接更多精彩内容