Skip to content

Instantly share code, notes, and snippets.

@ahmedshahriar
Last active July 9, 2021 00:11
Show Gist options
  • Save ahmedshahriar/37e3a16bc46cbf03adef4d5d67fbf4bf to your computer and use it in GitHub Desktop.
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
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