TL;DR: Is this expected behavior?
Not at all similar to Python multiprocessing with start method 'spawn' doesn't work, which is the closest existing question I could find.
To be precise, here is a MWI I am using to test:
import multiprocessing as mp
def fun_computation(x, output):
acc = 0
for i in range(x):
acc += i * i
output.value = acc
def main():
shared = mp.Value("i", -1)
proc = mp.Process(target=fun_computation, args=(100, shared))
proc.start()
proc.join()
assert(shared.value >= 0)
print(shared.value)
if __name__ == "__main__":
mp.set_start_method('spawn')
main()
And this is the output I get:
❯ python mptest.py
328350
❯ env -i python mptest.py
/usr/lib/python3.8/multiprocessing/resource_tracker.py:96: UserWarning: resource_tracker: process died unexpectedly, relaunching. Some resources might leak.
warnings.warn('resource_tracker: process died unexpectedly, '
Traceback (most recent call last):
File "mptest.py", line 19, in <module>
main()
File "mptest.py", line 14, in main
assert(shared.value >= 0)
AssertionError
❯ python -V
Python 3.8.3
This was tested on an up-to-date Arch Linux installation (at the time of writing). I have yet to test it on Windows and do not have access to macOS. Normal python scripts (e.g., calling fun_computation w/o the multiprocessing) work fine.
Sorry if this example seems a little convoluted; the real error is a byproduct of many more systems interfacing together, but this demonstrates the issue I am having.
TL;DR: Is this expected behavior?