Discuss / Python / 这章Windows环境下很多结果跟老师的不一样啊,子进程都没执行或者没有显示结果

这章Windows环境下很多结果跟老师的不一样啊,子进程都没执行或者没有显示结果

Topic source

Gin阿金

#1 Created at ... [Delete] [Delete and Lock User]

from multiprocessing import Process import os

子进程要执行的代码

def run_proc(name): print('Run child process %s (%s)...' % (name, os.getpid()))

if name=='main': print('Parent process %s.' % os.getpid()) p = Process(target=run_proc, args=('test',)) print('Child process will start.') p.start() p.join() print('Child process end.')

Parent process 13940. Child process will start. Child process end.

from multiprocessing import Process import os

def run_proc(name): print('Run child process %s ( %s )...' %(name, os.getpid()))

if __name__ == '__main__': print('Parent process %s' % os.getpid()) p = Process(target=run_proc, args = ('test',)) print('Child process will start') p.start() p.join() print('Child process end')

运行结果: Parent process 19852 Child process will start Run child process test ( 15304 )... Child process end

Gin阿金

#3 Created at ... [Delete] [Delete and Lock User]

@御坂美琴0001号,是win10环境下的结果吗? 回复没注意,实际我是有_,而且复制了你的代码跑还是没有

Run child process test ( xxx)...

我是win10,python3.7跟anaconda3尝试过,还是不行,不知道什么原因

要关注S

#4 Created at ... [Delete] [Delete and Lock User]

在windows powershell里面运行可以显示

Gin阿金

#5 Created at ... [Delete] [Delete and Lock User]

总算搞明白了,谢谢各位

我也碰到这种情况。请问是什么原因呢?谢谢了


  • 1

Reply