Skip to content

Instantly share code, notes, and snippets.

@1pha
Created January 12, 2023 00:42
Show Gist options
  • Save 1pha/0292ff42771fac5b02703f8fb7317608 to your computer and use it in GitHub Desktop.
Save 1pha/0292ff42771fac5b02703f8fb7317608 to your computer and use it in GitHub Desktop.
How to access global variable when using multiprocessing in python
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