<分区>
def sample():
pass
Process(target=sample).start()
Process(target=sample).start()
上述代码因错误而失败:
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
但是这段代码运行良好:
def sample():
pass
if __name__ == '__main__':
Process(target=sample).start()
Process(target=sample).start()
为什么在这种情况下主模块会影响我的代码执行?我无法正确理解错误消息。
注意:我经历了What does if __name__ == "__main__": do?但无法理解它与我的代码的相关性。