码迷,mamicode.com
首页 > 其他好文 > 详细

利用process传参

时间:2018-11-09 20:58:14      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:for   live   ESS   RoCE   The   name   time   rom   targe   

#进程函数的使用
from multiprocessing import Process 
from time import sleep

a = 1

def worker(sec,msg):
    #当worker作为子进程运行时,对全局量a 的修改只会
    #影响在子进程中a的值 ,对父进程没有影响
    global a 
    a = 1000
    for i in range(3):
        sleep(sec)
        print("the worker msg",msg)
    print(a)

p = Process(name = 'worker',    target = worker,args = (2,),    kwargs = {'msg':'You are a big man'})

p.start()

#进程名称
print("进程名称:",p.name)
print("进程PID:",p.pid)
print('进程状态:',p.is_alive())

p.join()
print('parent:',a)

利用process传参

标签:for   live   ESS   RoCE   The   name   time   rom   targe   

原文地址:https://www.cnblogs.com/-hjj/p/9936712.html

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