Created
October 21, 2023 09:43
-
-
Save j-thepac/14404e7e1144905a771355fac9a088f1 to your computer and use it in GitHub Desktop.
Find sum by using common Aggregator
This file contains hidden or 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 | |
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