- 浏览: 2664889 次
- 来自: 杭州
文章分类
- 全部博客 (1188)
- webwork (4)
- 网摘 (18)
- java (103)
- hibernate (1)
- Linux (85)
- 职业发展 (1)
- activeMQ (2)
- netty (14)
- svn (1)
- webx3 (12)
- mysql (81)
- css (1)
- HTML (6)
- apache (3)
- 测试 (2)
- javascript (1)
- 储存 (1)
- jvm (5)
- code (13)
- 多线程 (12)
- Spring (18)
- webxs (2)
- python (119)
- duitang (0)
- mongo (3)
- nosql (4)
- tomcat (4)
- memcached (20)
- 算法 (28)
- django (28)
- shell (1)
- 工作总结 (5)
- solr (42)
- beansdb (6)
- nginx (3)
- 性能 (30)
- 数据推荐 (1)
- maven (8)
- tonado (1)
- uwsgi (5)
- hessian (4)
- ibatis (3)
- Security (2)
- HTPP (1)
- gevent (6)
- 读书笔记 (1)
- Maxent (2)
- mogo (0)
- thread (3)
- 架构 (5)
- NIO (5)
- 正则 (1)
- lucene (5)
- feed (4)
- redis (17)
- TCP (6)
- test (0)
- python,code (1)
- PIL (3)
- guava (2)
- jython (4)
- httpclient (2)
- cache (3)
- signal (1)
- dubbo (7)
- HTTP (4)
- json (3)
- java socket (1)
- io (2)
- socket (22)
- hash (2)
- Cassandra (1)
- 分布式文件系统 (5)
- Dynamo (2)
- gc (8)
- scp (1)
- rsync (1)
- mecached (0)
- mongoDB (29)
- Thrift (1)
- scribe (2)
- 服务化 (3)
- 问题 (83)
- mat (1)
- classloader (2)
- javaBean (1)
- 文档集合 (27)
- 消息队列 (3)
- nginx,文档集合 (1)
- dboss (12)
- libevent (1)
- 读书 (0)
- 数学 (3)
- 流程 (0)
- HBase (34)
- 自动化测试 (1)
- ubuntu (2)
- 并发 (1)
- sping (1)
- 图形 (1)
- freemarker (1)
- jdbc (3)
- dbcp (0)
- sharding (1)
- 性能测试 (1)
- 设计模式 (2)
- unicode (1)
- OceanBase (3)
- jmagick (1)
- gunicorn (1)
- url (1)
- form (1)
- 安全 (2)
- nlp (8)
- libmemcached (1)
- 规则引擎 (1)
- awk (2)
- 服务器 (1)
- snmpd (1)
- btrace (1)
- 代码 (1)
- cygwin (1)
- mahout (3)
- 电子书 (1)
- 机器学习 (5)
- 数据挖掘 (1)
- nltk (6)
- pool (1)
- log4j (2)
- 总结 (11)
- c++ (1)
- java源代码 (1)
- ocr (1)
- 基础算法 (3)
- SA (1)
- 笔记 (1)
- ml (4)
- zokeeper (0)
- jms (1)
- zookeeper (5)
- zkclient (1)
- hadoop (13)
- mq (2)
- git (9)
- 问题,io (1)
- storm (11)
- zk (1)
- 性能优化 (2)
- example (1)
- tmux (1)
- 环境 (2)
- kyro (1)
- 日志系统 (3)
- hdfs (2)
- python_socket (2)
- date (2)
- elasticsearch (1)
- jetty (1)
- 树 (1)
- 汽车 (1)
- mdrill (1)
- 车 (1)
- 日志 (1)
- web (1)
- 编译原理 (1)
- 信息检索 (1)
- 性能,linux (1)
- spam (1)
- 序列化 (1)
- fabric (2)
- guice (1)
- disruptor (1)
- executor (1)
- logback (2)
- 开源 (1)
- 设计 (1)
- 监控 (3)
- english (1)
- 问题记录 (1)
- Bitmap (1)
- 云计算 (1)
- 问题排查 (1)
- highchat (1)
- mac (3)
- docker (1)
- jdk (1)
- 表达式 (1)
- 网络 (1)
- 时间管理 (1)
- 时间序列 (1)
- OLAP (1)
- Big Table (0)
- sql (1)
- kafka (1)
- md5 (1)
- springboot (1)
- spring security (1)
- Spring Boot (3)
- mybatis (1)
- java8 (1)
- 分布式事务 (1)
- 限流 (1)
- Shadowsocks (0)
- 2018 (1)
- 服务治理 (1)
- 设计原则 (1)
- log (0)
- perftools (1)
最新评论
-
siphlina:
课程——基于Python数据分析与机器学习案例实战教程分享网盘 ...
Python机器学习库 -
san_yun:
leibnitz 写道hi,我想知道,无论在92还是94版本, ...
hbase的行锁与多版本并发控制(MVCC) -
leibnitz:
hi,我想知道,无论在92还是94版本,更新时(如Puts)都 ...
hbase的行锁与多版本并发控制(MVCC) -
107x:
不错,谢谢!
Latent Semantic Analysis(LSA/ LSI)算法简介 -
107x:
不错,谢谢!
Python机器学习库
## {{{ http://code.activestate.com/recipes/203871/ (r3) import threading from time import sleep # Ensure booleans exist (not needed for Python 2.2.1 or higher) try: True except NameError: False = 0 True = not False class ThreadPool: """Flexible thread pool class. Creates a pool of threads, then accepts tasks that will be dispatched to the next available thread.""" def __init__(self, numThreads): """Initialize the thread pool with numThreads workers.""" self.__threads = [] self.__resizeLock = threading.Condition(threading.Lock()) self.__taskLock = threading.Condition(threading.Lock()) self.__tasks = [] self.__isJoining = False self.setThreadCount(numThreads) def setThreadCount(self, newNumThreads): """ External method to set the current pool size. Acquires the resizing lock, then calls the internal version to do real work.""" # Can't change the thread count if we're shutting down the pool! if self.__isJoining: return False self.__resizeLock.acquire() try: self.__setThreadCountNolock(newNumThreads) finally: self.__resizeLock.release() return True def __setThreadCountNolock(self, newNumThreads): """Set the current pool size, spawning or terminating threads if necessary. Internal use only; assumes the resizing lock is held.""" # If we need to grow the pool, do so while newNumThreads > len(self.__threads): newThread = ThreadPoolThread(self) self.__threads.append(newThread) newThread.start() # If we need to shrink the pool, do so while newNumThreads < len(self.__threads): self.__threads[0].goAway() del self.__threads[0] def getThreadCount(self): """Return the number of threads in the pool.""" self.__resizeLock.acquire() try: return len(self.__threads) finally: self.__resizeLock.release() def queueTask(self, task, args=None, taskCallback=None): """Insert a task into the queue. task must be callable; args and taskCallback can be None.""" if self.__isJoining == True: return False if not callable(task): return False self.__taskLock.acquire() try: self.__tasks.append((task, args, taskCallback)) return True finally: self.__taskLock.release() def getNextTask(self): """ Retrieve the next task from the task queue. For use only by ThreadPoolThread objects contained in the pool.""" self.__taskLock.acquire() try: if self.__tasks == []: return (None, None, None) else: return self.__tasks.pop(0) finally: self.__taskLock.release() def joinAll(self, waitForTasks = True, waitForThreads = True): """ Clear the task queue and terminate all pooled threads, optionally allowing the tasks and threads to finish.""" # Mark the pool as joining to prevent any more task queueing self.__isJoining = True # Wait for tasks to finish if waitForTasks: while self.__tasks != []: sleep(.1) # Tell all the threads to quit self.__resizeLock.acquire() try: self.__setThreadCountNolock(0) self.__isJoining = True # Wait until all threads have exited if waitForThreads: for t in self.__threads: t.join() del t # Reset the pool for potential reuse self.__isJoining = False finally: self.__resizeLock.release() class ThreadPoolThread(threading.Thread): """ Pooled thread class. """ threadSleepTime = 0.1 def __init__(self, pool): """ Initialize the thread and remember the pool. """ threading.Thread.__init__(self) self.__pool = pool self.__isDying = False def run(self): """ Until told to quit, retrieve the next task and execute it, calling the callback if any. """ while self.__isDying == False: cmd, args, callback = self.__pool.getNextTask() # If there's nothing to do, just sleep a bit if cmd is None: sleep(ThreadPoolThread.threadSleepTime) elif callback is None: cmd(args) else: callback(cmd(args)) def goAway(self): """ Exit the run loop next time through.""" self.__isDying = True # Usage example if __name__ == "__main__": from random import randrange # Sample task 1: given a start and end value, shuffle integers, # then sort them def sortTask(data): print "SortTask starting for ", data numbers = range(data[0], data[1]) for a in numbers: rnd = randrange(0, len(numbers) - 1) a, numbers[rnd] = numbers[rnd], a print "SortTask sorting for ", data numbers.sort() print "SortTask done for ", data return "Sorter ", data # Sample task 2: just sleep for a number of seconds. def waitTask(data): print "WaitTask starting for ", data print "WaitTask sleeping for %d seconds" % data sleep(data) return "Waiter", data # Both tasks use the same callback def taskCallback(data): print "Callback called for", data # Create a pool with three worker threads pool = ThreadPool(3) # Insert tasks into the queue and let them run pool.queueTask(sortTask, (1000, 100000), taskCallback) pool.queueTask(waitTask, 5, taskCallback) pool.queueTask(sortTask, (200, 200000), taskCallback) pool.queueTask(waitTask, 2, taskCallback) pool.queueTask(sortTask, (3, 30000), taskCallback) pool.queueTask(waitTask, 7, taskCallback) # When all tasks are finished, allow the threads to terminate pool.joinAll() ## end of http://code.activestate.com/recipes/203871/ }}}
发表评论
-
python读取图片exif信息
2014-11-06 10:53 2407f = open("/home/admin/tlo ... -
Python程序的执行原理
2014-04-14 15:44 17341. 过程概述 Python先把代码(.py文件)编译成字 ... -
如何创建一个短链服务
2013-12-26 16:23 0参考: http://stackoverflow.com ... -
python 解析命令参数(argument)组件argparse
2013-12-11 17:35 1411参考: http://youngsterxyf.githu ... -
pyhon命令行工具optparse
2013-11-10 16:27 1048使用python optparse 可以创建命令行工具,下面 ... -
Python在豆瓣的应用
2013-10-21 10:46 1209Python在豆瓣的应用,hongqiangning分享 ... -
用python爬虫抓站的一些技巧总结
2013-10-10 14:12 1687学用python也有3个多月了,用得最多的还是各类爬虫 ... -
python小技巧
2013-10-10 11:50 7511. 声明长度256的数组 a=[0]*256 ... -
使用tesseract-ocr破解网站验证码
2013-10-09 10:25 1216原文:使用tesseract-ocr破解网站验证码 ... -
和豆瓣CMGS交流
2013-06-20 17:36 5857蒋云鹏: 在?CMGS: 在蒋 ... -
python乱码问题('ascii' codec can't encode character u'\u4e2d' in position 0)
2013-05-20 19:03 4260>>> k = u'中' >> ... -
python shell 交互模式
2013-04-28 22:17 1647python 通过code模块可以很容易的进入交互模式: ... -
jython和gunicorn性能测试对比
2013-04-13 13:03 1315helloworld,笔记本上: gunicorn ... -
python的mysql客户端-MySQLdb
2013-04-04 10:13 1176平时的主要编程语言是Java,开发时也主要用Mysql,经常 ... -
Python几种并发实现方案的性能比较
2013-03-18 21:14 2970原文:http://www.elias.cn/P ... -
python汉字和Unicode码(utf-8)之间的转换(Pack/Unpack)
2013-03-18 21:13 1654保证你要转换的字符串编码为UTF8,如果不是,请iconv ... -
python反序列化的坑
2013-01-06 18:06 1287今天遇到python一个坑,调用memcached的get_m ... -
sqlalchemy connection pool.py 源代码
2012-12-29 22:58 2259把 sqlalchemy pool源代码copy下来,有空看看 ... -
SQLAlchemy简单介绍
2012-12-28 22:41 0文档参考:http://docs.sqlalchemy.org ... -
pymysql简单使用
2012-12-28 12:38 2126import pymysql conn = pymysq ...
相关推荐
Generic Programming(泛型程序设计小手册)中文chm版
Modern C++ Design: Generic Programming and Design Patterns Applied By Andrei Alexandrescu Publisher : Addison Wesley Pub Date : February 01, 2001 ISBN : 0-201-70431-5 ...
Displaying extraordinary creativity and programming virtuosity, Alexandrescu offers a cutting-edge approach to design that unites design patterns, generic programming, and C++, enabling programmers ...
这是一本内容丰富而又通俗易懂的书籍,由优秀的软件设计师 Alexander A. Stepanov 与其同事 Daniel E. Rose 所撰写。作者在书中解释泛型编程的原则及其所依据的抽象数学概念,以帮助你写出简洁而强大的代码。
《Modern C++ Design: Generic Programming and Design Patterns Applied》是由 Andrei Alexandrescu 编写的一本关于 C++ 的高级技术书籍,该书由 Addison Wesley 出版社于 2001 年 2 月出版,ISBN 为 0-201-70431-5...
关于STL编程比较好的一本书,中文的,个人认为还是比较清楚的^^
<<generic programming and the stl>>让你从oo向gp转变 光用不行,我们还有必要了解stl的工作原理,那么源码剖析>>会解决你所有的困惑 level 5 对于c++无非是oo和gp,想进一步提升oo,<<exeptional c++ style>>是一...
许多程序员可能并不知道,C++不仅是一个面向对象程序语言, 它还适用于泛型编程(generic programming)。这项技术可以大大增强你的能力,协助你写出高效率并可重复运用的软件组件(software components)。 本书由...
《现代C++设计:泛型编程与设计模式应用》是一本由Andrei Alexandrescu编写的经典著作,它深入探讨了C++中的高级设计技术,尤其是泛型编程和设计模式的应用。这本书对于想要提升C++编程技能的专业人士来说,是一份不...
通用编程(Generic Programming)是一种编程范式,它的核心思想是编写可重用的、不依赖特定数据类型的代码。这种编程方式允许程序员创建独立于具体数据类型的算法和数据结构,从而提高了代码的灵活性和可维护性。在...
Modern C++ Design Generic Programming and Design Patterns Applied 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
泛型编程(Generic Programming)作为一种编程范式,其核心在于设计出可重用且高效的算法集合。它不仅仅局限于特定的数据类型,而是通过参数化类型的方式使得同一段代码可以处理多种数据结构。这种能力在现代软件...
《Generic Programming with Haskell》是一本由Roland Backhouse和Jeremy Gibbons编辑的书籍,属于Lecture Notes in Computer Science系列(第2793卷)。该书由Springer出版社出版,并在2003年正式发行。本书探讨了...
通用编程(Generic Programming)是一种编程范式,它允许开发者创建高度可重用的软件库。其中,C++是实现通用编程的典型语言之一。本文探讨了算法专业化在通用编程中的应用,并提出了一种针对C++的受限泛型扩展。 *...