Repository: pytorch
Issue: repeat_interleave hangs in a forked subprocess
Labels: module: multiprocessing,triaged

## 🐛 Bug

The function repeat_interleave hangs in a forked subprocess. Please see the code example below

## To Reproduce

Steps to reproduce the behavior:

```python
import queue
import torch
from multiprocessing import Queue, get_context


def worker_function(_queue: Queue = None):
    x = torch.tensor([1, 2, 3])
    y = x.repeat_interleave(2)
    if _queue is not None:
        _queue.put(y.tolist())
    else:
        return y.tolist()


def completely_independent_function(_queue: Queue = None):
    x = torch.tensor([1, 2, 3])
    y = x.repeat_interleave(2)
    if _queue is not None:
        _queue.put(y.tolist())
    else:
        return y.tolist()


def main(context: str):
    ctx = get_context(context)
    q = ctx.Queue()
    p = ctx.Process(target=worker_function, args=(q,))
    p.start()
    result = q.get(timeout=10)
    p.join()
    return result


if __name__ == '__main__':
    print("Start")
    i = completely_independent_function()
    print("Finished completely_independent_function in the main process")
    for method in ['fork', 'forkserver', 'spawn']:
        try:
            r = main(method)
            assert i == r
            print(f"The '{method}' method succeed")
        except queue.Empty:
            print(f"The '{method}' hangs due to unknown reason")

```

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

The "fork" method does not hang or the timeout value can be omitted.

## Environment

Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)
(or fill out the checklist below manually).

You can get the script and run it with:
```
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```

Collecting environment information...
PyTorch version: 1.10.0+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.3 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31

Python version: 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:23:11)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.11.0-40-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce RTX 2060
Nvidia driver version: 460.91.03
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.4
[pip3] pytorch-lightning==1.5.3
[pip3] torch==1.10.0
[pip3] torch-cluster==1.5.9
[pip3] torch-geometric==2.0.2
[pip3] torch-scatter==2.0.9
[pip3] torch-sparse==0.6.12
[pip3] torch-spline-conv==1.2.1
[pip3] torchmetrics==0.6.0
[conda] mypy-extensions           0.4.3                    pypi_0    pypi
[conda] numpy                     1.21.4           py39hdbf815f_0    conda-forge
[conda] pytorch-lightning         1.5.3                    pypi_0    pypi
[conda] torch                     1.10.0                   pypi_0    pypi
[conda] torch-cluster             1.5.9                    pypi_0    pypi
[conda] torch-geometric           2.0.2                    pypi_0    pypi
[conda] torch-scatter             2.0.9                    pypi_0    pypi
[conda] torch-sparse              0.6.12                   pypi_0    pypi
[conda] torch-spline-conv         1.2.1                    pypi_0    pypi
[conda] torchmetrics              0.6.0                    pypi_0    pypi

Process finished with exit code 0


## Additional context

<!-- Add any other context about the problem here. -->
* The error occurs on CPU only
* We faced it [here](https://github.com/pyg-team/pytorch_geometric/issues/3565).


cc @VitalyFedyunin