5,321
edits
Line 336: | Line 336: | ||
from concurrent.futures import ThreadPoolExecutor | from concurrent.futures import ThreadPoolExecutor | ||
executor = ThreadPoolExecutor(max_workers= | executor = ThreadPoolExecutor(max_workers=2 * os.cpu_count()) | ||
def do_something(a, b): | def do_something(a, b): | ||
return a + b | return a + b | ||
Line 346: | Line 346: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* <code>len(os.sched_getaffinity(0))</code> returns the number of threads available to the Python process | * <code>len(os.sched_getaffinity(0))</code> returns the number of threads available to the Python process. | ||
* Starting in Python 3.5, if <code>max_workers</code> is none, it defaults to 5 | * Starting in Python 3.5, if <code>max_workers</code> is none, it defaults to <code>5 * os.cpu_count()</code>. | ||
==Data Structures== | ==Data Structures== |