5,321
edits
Line 344: | Line 344: | ||
future = self.executor.submit(do_something, 1, 2+i) | future = self.executor.submit(do_something, 1, 2+i) | ||
futures.append(future) | futures.append(future) | ||
while len(futures) > 0: | |||
future = futures.pop() | |||
future.result() | |||
executor.shutdown() | |||
</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 <code>5 * os.cpu_count()</code>. | * Starting in Python 3.5, if <code>max_workers</code> is none, it defaults to <code>5 * os.cpu_count()</code>. | ||
* <code>executor.shutdown()</code> will wait for all jobs to finish but you cannot submit any additional jobs, even from other threads, after calling shutdown. | |||
==Data Structures== | ==Data Structures== |