Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Created October 21, 2023 09:43
Show Gist options
  • Save j-thepac/14404e7e1144905a771355fac9a088f1 to your computer and use it in GitHub Desktop.
Save j-thepac/14404e7e1144905a771355fac9a088f1 to your computer and use it in GitHub Desktop.
Find sum by 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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment