在最近在学python的进程,因为一直在linux下学的,今天到win下测试了一下,发下了个问题代码如下
  
import multiprocessing as mp
import time
import os


def th():
print("我的父亲是%d" % os.getppid())
time.sleep(2)
while True:
time.sleep(2)
print("我是儿子!")
print("我的父亲是%d" % os.getppid())


p = mp.Process(target=th)
p.daemon = False
p.start()
time.sleep(1)
print("爸爸我over了!", os.getpid())


这段代码在linux运行无错误但是在win下
python multiprocessing 模块Process类的target函数






后来我发现在代码里面加一个逻辑控制的 if __name__ == 'main'就可以解决了









欢迎大牛批评教导,解决疑惑,谢谢




 

相关文章:

  • 2021-11-29
  • 2022-01-24
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
猜你喜欢
  • 2021-06-23
  • 2022-12-23
  • 2021-10-16
  • 2021-12-15
  • 2022-02-26
  • 2021-11-23
相关资源
相似解决方案