Created
January 12, 2023 00:42
-
-
Save 1pha/0292ff42771fac5b02703f8fb7317608 to your computer and use it in GitHub Desktop.
How to access global variable when using multiprocessing in python
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 multiprocessing as mp | |
def add(val): | |
list_proxy.append(val) | |
print(list_proxy) | |
if __name__=="__main__": | |
man = mp.Manager() | |
list_proxy = man.list() | |
with mp.Pool(processes=2) as p: | |
p.map(func=add, iterable=range(40)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment