I’m consistently getting segfaults with the following code:
import torch.multiprocessing as mp


def main(pidish, q):
  print(q.get())

if __name__ == '__main__':
  q = mp.Queue()
  mp.spawn(main, args=(q,), nprocs=1)

I’ve tried this with PyTorch 1.4 and 1.5 in a fresh conda environment on two separate Ubuntu 18.04 machines and get segfaults like below:
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    mp.spawn(main, args=(q,), nprocs=1)
  File "/home/sharvil/.miniconda2/envs/torch-1.5/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 200, in spawn
    return start_processes(fn, args, nprocs, join, daemon, start_method='spawn')
  File "/home/sharvil/.miniconda2/envs/torch-1.5/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 158, in start_processes
    while not context.join():
  File "/home/sharvil/.miniconda2/envs/torch-1.5/lib/python3.8/site-packages/torch/multiprocessing/spawn.py", line 106, in join
    raise Exception(
Exception: process 0 terminated with signal SIGSEGV

I’m expecting a deadlock since the queue is empty but surely this trivial example shouldn’t segfault… What am I missing here? Can anyone else repro this?