Skip to content

Cannot modify global variable #33

Open
@gtimoshaz

Description

@gtimoshaz

I have the following code:

import p_tqdm
d = dict()

def modify_dict(a):
    d[a] = a ** 2

p_tqdm.p_map(modify_dict, list(range(10)))
print(d)

It outputs {} instead of {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}.

In comparasion, concurrent.futures works as expected:

import concurrent.futures
with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor:
     executor.map(modify_dict, list(range(10)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions