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

python 进程锁

时间:2019-01-29 12:50:48      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:proc   __name__   one   style   time   target   ssi   name   from   

 

1.

#_*_coding:utf-8_*_
from  multiprocessing import Process,Lock
import os,time
def f(l,i):
    #加锁
    l.acquire()
    print(hello,i)
    #释放锁
    l.release()
if __name__ == __main__:
    lock=Lock()
    for i in range(5):
           p=Process(target=f,args=(lock,i)).start()

输出

hello 4
hello 1
hello 2
hello 0
hello 3

 

python 进程锁

标签:proc   __name__   one   style   time   target   ssi   name   from   

原文地址:https://www.cnblogs.com/sea-stream/p/10333493.html

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