python3中在windows10中创建进程

python3中在windows10中创建进程

Windows使用mulprocess模块来进行进程调用,但会在父进程copy子进程时会出现子进程并非父进程ID+1的境况,这是操作系统的问题,官网文档给出了解释
https://docs.python.org/2/library/multiprocessing.html?highlight=process#windows

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 3908.
Child process will start.
Run child process test (3664)…
Child process end.

你可能感兴趣的:(python3中在windows10中创建进程)