Skip to content

Instantly share code, notes, and snippets.

@akiraak
Last active October 1, 2017 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akiraak/c64b4e4bab58724d821d09e35662a854 to your computer and use it in GitHub Desktop.
Save akiraak/c64b4e4bab58724d821d09e35662a854 to your computer and use it in GitHub Desktop.
Pythonでシンプルにステッド処理
import os
import concurrent.futures as confu
def target_func(x):
return x + 1
def main():
count = 10
with confu.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
fs = {executor.submit(target_func, x): x for x in range(count)}
for f in confu.as_completed(fs):
print(fs[f], f.result())
if __name__ == "__main__":
main()
"""
$ python thread.py
2 3
1 2
0 1
3 4
4 5
5 6
6 7
7 8
8 9
9 10
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment