我的理解是 tpool 为您提供了一个本地线程池,而 Greenpool 为您提供了绿色线程池(基本上所有绿色线程都在一个本地线程中)。
池
def my_func(start_ident): print "start_ident:%s" % start_ident print "running in new thread: %s %s" % (start_ident != thread.get_ident(), thread.get_ident()) tpool.execute(my_func, thread.get_ident()
结果:不同的本机线程
start_ident:140735259603328 running in new thread: True 4616945664
格林普尔
def worker(line): print "worker in thread %s" % thread.get_ident() return line pool = GreenPool() for result in pool.imap(worker, open("test.txt", 'r')): print result
结果:绿色线程在同一本机线程中运行
worker in thread 140735259603328 worker in thread 140735259603328 worker in thread 140735259603328 worker in thread 140735259603328 .......
有人可以指出我何时使用一个池与另一个池。