首页 > 编程语言 > 详细

Python锁

时间:2017-06-03 20:33:16      阅读:284      评论:0      收藏:0      [点我收藏+]

  

# coding:utf-8
import threading
import time


def test_xc():
    f = open("test.txt","a")
    f.write("test_dxc"+\n)
    time.sleep(1)
    mutex.acquire()#取得锁
    f.close()
    mutex.release()#释放锁

if __name__ == __main__:
    mutex = threading.Lock()#创建锁
    for i in xrange(5):
        t = threading.Thread(target=test_xc)
        t.start()

 

Python锁

原文:http://www.cnblogs.com/413xiaol/p/6938258.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!