使用python测试你的电脑开启最大线程数
2016-07-11 11:01
531 查看
#!/usr/bin/env python #coding=gbk import threading import time, random, sys class Counter: def __init__(self): self.lock = threading.Lock() self.value = 0 def increment(self): self.lock.acquire() self.value = value = self.value + 1 self.lock.release() return value counter = Counter() cond = threading.Condition() class Worker(threading.Thread): def run(self): print self.getName(), "-- created." cond.acquire() #for i in range(10): # pretend we're doing something that takes 10?00 ms #value = counter.increment() # time.sleep(random.randint(10, 100) / 1000.0) cond.wait() #print self.getName(), "-- task", "finished" cond.release() if __name__ == '__main__': try: for i in range(3500): Worker().start() # start a worker except BaseException, e: print "异常: ", type(e), e time.sleep(5) print "maxium i=", i finally: cond.acquire() cond.notifyAll() cond.release() time.sleep(3) print threading.currentThread().getName(), " quit"
相关文章推荐
- Python爬虫实战(3):安居客房产经纪人信息采集
- Python获取当前时间的前(后)N天,前(后)N周,前(后)N月
- Python新手学习基础之数据类型——变量
- 深入Python(2): __init__.py 用法
- TensorFlow实战— —K-Means聚类
- Celery 踩坑笔记
- DAY7:leetcode #14 Longest Common Prefix
- Python中关于字符串问题
- 关于python urlopen 一个类似radio流的timeout方法
- python平行(3):【parallel python】与【sklearn joblib的parallel和delayed】性能对比
- [Jenkins] Use python requests to programatically get and set Jenkins job configuration
- python安装第三方插件出现的错误
- 爬虫笔记
- 一个程序学会python的流程控制
- mac 安装robotFramwork环境 以及wxPython 无法安装问题解决 (非常有用)
- Python collections模块实例讲解
- Python编写简单的HTML页面合并脚本
- Python中super()函数简介及用法分享
- python关于列表转为字典的两个小方法
- python常用代码片