码迷,mamicode.com
首页 > 编程语言 > 详细

python基础:多进程讲解

时间:2017-12-28 11:58:23      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:style   color   ret   blog   方法   nbsp   其他   没有   note   

fork的使用方法:

import os 
import time

# 主进程执行到os.fork()会产生一个子进程。ret>0,代表主进程;ret=0,代表子进程
ret=os.fork() # 从这句开始,父进程和子进程都会执行以下的代码
print(ret)
if ret>0:
    print(---父进程--{}-.format(os.getpid))
    time.sleep(1)
else:
    print(---子进程-{}-{}-.format(os.getpid,os.getppid()))
    time.sleep(1)

note:fork只能在linux平台下使用,其他平台没有该方法。

 

python基础:多进程讲解

标签:style   color   ret   blog   方法   nbsp   其他   没有   note   

原文地址:https://www.cnblogs.com/hypnus-ly/p/8129205.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!