I was having a problem with some more complex code but have reduced it to something that reproduces the issue:
from multiprocessing import Manager
from concurrent.futures import ProcessPoolExecutor
from itertools import repeat
def process(v):
v.value += 1
def main():
with Manager() as manager:
v = manager.Value('i', 0)
with ProcessPoolExecutor() as executor:
executor.map(process, repeat(v, 10))
print(v.value)
if __name__ == '__main__':
main()
The value I expect to be printed is 10.
But here's the issue... It is 10 most of the time but sometimes it's 9 or even 8.
From the documentation:- "A manager object returned by Manager() controls a server process which holds Python objects and allows other processes to manipulate them using proxies"
This behaviour suggests that the "server process" is unreliable in my environment.
I'm guessing that this is either a bug in my version of Python or an issue that's peculiar to macOS.
Environment details: Python 3.10.2, macOS 12.2.1, 3 GHz 10-Core Intel Xeon W, 32gb RAM
Or maybe I've fundamentally misunderstood something