def sample():
pass
Process(target=sample).start()
Process(target=sample).start()
The above code fails with an error:
An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module
But this code runs fine:
def sample():
pass
if __name__ == '__main__':
Process(target=sample).start()
Process(target=sample).start()
Why does the main module affect my code execution in this case? I am unable to understand the error message properly.
Note: I went through What does if __name__ == "__main__": do? but could not understand its relevance to my code.