Last active
July 9, 2021 00:11
-
-
Save ahmedshahriar/37e3a16bc46cbf03adef4d5d67fbf4bf to your computer and use it in GitHub Desktop.
This python script will map a list (length 10 for 10 executor) and execute 10 concurrent processes using concurrent module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures | |
def test(li): | |
# print('hello world') | |
if li: | |
print('hello world', li) | |
def run_all(li): | |
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: | |
executor.map(test, li) | |
li = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
run_all(li) | |
""" | |
# one possible output | |
hello world 1 | |
hello world 2 | |
hello world 3 | |
hello world 4 | |
hello world 6 | |
hello world 7 | |
hello world 5 | |
hello world 9 | |
hello world 10 | |
hello world 8 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment