Error using multiprocessing module:
from multiprocessing import Process
def hello():
print('hello')
p = Process(target=hello)
p.start()
Change the code to:
from multiprocessing import Process, freeze_support, set_start_method
def hello():
print('hello')
if __name__ == '__main__':
p = Process(target=hello)
p.start()
Which if __name__ == '__main__':
role is to protect the program entry point , when a sub-process using open Process, Python interpreter into the current module, and invoke the hello method, using a simple intuitive test:
from multiprocessing import Process, freeze_support, set_start_method
def hello():
print('hello')
print("!!!")
if __name__ == '__main__':
p = Process(target=hello)
p.start()
In this code, Print ("!!"
is not a hello method. Let’s see the running result:
print("!!!")
was called twice!!! So before generating a new process, be sure to add if__ name__ == '__ main__':
!
Further, if you change print("!!!")
to print(__name__)
, you will get the following results:
Read More:
- RuntimeError: stack expects each tensor to be equal size, but got [x] at entry 0 and [x] at entry 1
- [Solved] RuntimeError: cuda runtime error (100) : no CUDA-capable device is detected at
- [Solved] RuntimeError: function ALSQPlusBackward returned a gradient different than None at position 3, but t
- Full explanation of SYS module of Python
- How to Solve RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu
- [Solved] RuntimeError: Numpy is not available (Associated Torch or Tensorflow)
- [Solved] RuntimeError: cublas runtime error : resource allocation failed at
- [Solved] RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cubla…
- Pytorch Error: runtimeerror: expected scalar type double but found float
- [How to Fix]RuntimeError: Python is not installed as a framework, If you are using (Ana)Conda
- Tensor for argument #2 ‘mat1‘ is on CPU, but expected it to be on GPU (while checking arguments for
- How to Solve RuntimeError: cuDNN error: CUDNN_STATUS_EXECUTION_FAILED
- [Solved] Python Error: asyncio RuntimeError: This event loop is already running
- [Solved] Python AssertionError: MMCV==1.1.0 is used but incompatible. Please install mmcv>=1.0.5, <=1.0.5.
- [Solved] RuntimeError: expected scalar type Long but found Float
- [Solved] pytorch loss.backward() Error: RuntimeError: Function AddBackward0 returned an invalid gradient at index 1…
- Python IndexError: too many indices for array: array is 1-dimensional, but 2 were i..
- [Solved] RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm
- [Solved] RuntimeError: cuda runtime error (801) : operation not supported at
- [Solved] RuntimeError: ProcessGroupNCCL is only supported with GPUs, no GPUs found