首页 > 编程语言 > 详细

Python线程锁

时间:2017-03-24 17:31:41      阅读:144      评论:0      收藏:0      [点我收藏+]
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线程锁

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

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