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

Python锁

时间:2017-06-03 20:52:01      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:star   color   ase   xrange   release   imp   UI   get   odi   

  

# 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锁

标签:star   color   ase   xrange   release   imp   UI   get   odi   

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

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