p = Process(target=run_proc, args = ('test',)) 子进程未执行

在学习python中的多进程时,发现如下代码子进程中的print无法打印出来,
在采用pdb调试时,发现每一步都走到了,感觉像是没显示出来,于是采用写文件的
方式,发现子进程的输出被写到文件中了,原来是ide不支持输入;

from multiprocessing import Process
import pdb
import os

def run_proc(name):
with open(r'C:UsersyangyiDesktop eet.txt', 'w') as f:
f.write('child process %s (%s)' % (name, os.getpid()))
'''print('child process %s (%s)' % (name, os.getpid()))'''

if name == 'main':
print('parent process %s' % os.getpid())

'''pdb.set_trace()'''

p = Process(target=run_proc, args = ('test',))

print('child process will start')
p.start()
p.join()
print('child process end.')
原文地址:https://www.cnblogs.com/yangyi54920/p/12931863.html