I really get confused when I use the function torch.multiprocessing.spawn. Consider the following code:
import torch
import torch.multiprocessing as mp


x = [1, 2]

def f(id, a):
    print(x)
    print(a)

if __name__ == '__main__':
    x.append(3)
    mp.spawn(f, nprocs=2, args=(x, ))

For any process the main function spwans, it outputs the following:
[1, 2]
[1, 2, 3]

I have the following questions:
(1) Why is the first line of output [1, 2]? I think x is a global variable, and fork new process will share the memory in linux, which follows this page: https://stackoverflow.com/questions/5983159/python-multiprocessing-arguments-deep-copy
(2) Are the parameters in spawn deep copied to the new processes? Or just pass a reference?
Thank you very much!