[Assorted-commits] SF.net SVN: assorted:[1841] sandbox/trunk/src/py
Brought to you by:
yangzhang
From: <yan...@us...> - 2012-10-01 21:41:41
|
Revision: 1841 http://assorted.svn.sourceforge.net/assorted/?rev=1841&view=rev Author: yangzhang Date: 2012-10-01 21:41:35 +0000 (Mon, 01 Oct 2012) Log Message: ----------- Demo of greedy thread pool map Added Paths: ----------- sandbox/trunk/src/py/greedythreadpool.py sandbox/trunk/src/py/thread_local_reuse.py Removed Paths: ------------- sandbox/trunk/src/py/multiprocessing.py Added: sandbox/trunk/src/py/greedythreadpool.py =================================================================== --- sandbox/trunk/src/py/greedythreadpool.py (rev 0) +++ sandbox/trunk/src/py/greedythreadpool.py 2012-10-01 21:41:35 UTC (rev 1841) @@ -0,0 +1,10 @@ +from __future__ import absolute_import +import concurrent.futures as fut, time +def f(): + with fut.ThreadPoolExecutor(4) as tpe: + start = time.time() + list(tpe.map(g, [1,3,1,1])) + print time.time() - start +def g(i): + time.sleep(i) +f() Deleted: sandbox/trunk/src/py/multiprocessing.py =================================================================== --- sandbox/trunk/src/py/multiprocessing.py 2012-09-19 10:28:15 UTC (rev 1840) +++ sandbox/trunk/src/py/multiprocessing.py 2012-10-01 21:41:35 UTC (rev 1841) @@ -1,8 +0,0 @@ -import threading -from concurrent.futures import * -g=threading.local() -def f(x): - if not hasattr(g, 'f'): - g.f = open('/tmp/foo','w') - print >> g.f, x -ProcessPoolExecutor(1).map(f, range(3)) Copied: sandbox/trunk/src/py/thread_local_reuse.py (from rev 1837, sandbox/trunk/src/py/multiprocessing.py) =================================================================== --- sandbox/trunk/src/py/thread_local_reuse.py (rev 0) +++ sandbox/trunk/src/py/thread_local_reuse.py 2012-10-01 21:41:35 UTC (rev 1841) @@ -0,0 +1,8 @@ +import threading +from concurrent.futures import * +g=threading.local() +def f(x): + if not hasattr(g, 'f'): + g.f = open('/tmp/foo','w') + print >> g.f, x +ProcessPoolExecutor(1).map(f, range(3)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |