首页 > 代码库 > Python线程锁
Python线程锁
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线程锁
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。