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

from multiprocessing import Process
import pdb
import os

def run\_proc(name):
with open(r'C:\Users\yangyi\Desktop\teet.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.')

标签: target, import, run, os, Process, child, process, name, print

相关文章推荐

添加新评论,含*的栏目为必填