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

Python线程锁

时间:2017-03-24 17:31:41      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:lock   cal   exception   reading   time()   localtime   UI   except   bsp   

mutex = threading.Lock() 
mutex.acquire()--锁住

mutex.release() --解锁
 
 

 

# coding:utf-8
import threading
import time
mutex = threading.Lock()
def write(scan_type, host, port, info):
    mutex.acquire()
    port = int(port)
    try:
        time_str = time.strftime(%X, time.localtime(time.time()))
        if scan_type == portscan:
            print "[%s] %s:%d open" % (time_str, host, port)
        elif scan_type == server:
            print "[%s] %s:%d is %s" % (time_str, host, port, str(info))
        elif scan_type == web:
            print "[%s] %s:%d is web" % (time_str, host, port)
            print "[%s] %s:%d web info %s" % (time_str, host, port, info)
        elif scan_type == active:
            print "[%s] %s active" % (time_str, host)
        elif scan_type == info:
            print "[%s] %s" % (time_str, info)
    except Exception, e:
        print logerror,e
        pass
    mutex.release()

 

Python线程锁

标签:lock   cal   exception   reading   time()   localtime   UI   except   bsp   

原文地址:http://www.cnblogs.com/bayueman/p/6612481.html

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