Saturday, October 21, 2023

Python : Find Sum using Parallel Procesing using Common Aggregator

import concurrent.futures
import threading
a=0
def fn(i):
global a
a=a+i
print(a,threading.get_native_id())
if __name__ == '__main__':
with concurrent.futures.ThreadPoolExecutor(3) as ep:
ep.map(fn, range(0, 100))
print("final " + str(a))
view raw MultiThread.py hosted with ❤ by GitHub

No comments:

Post a Comment