• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python threading.lock函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中threading.lock函数的典型用法代码示例。如果您正苦于以下问题:Python lock函数的具体用法?Python lock怎么用?Python lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了lock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: delete_neighbor

 def delete_neighbor(self, key, neighbor):
     with lock():
         for p in self.peer['prefixes']:
             if p['prefix'] == key and p['next_hop'] == neighbor:
                 self.peer['prefix'].remove(p)
                 self.db['peers'].save(self.peer)
                 break
开发者ID:rafaelsilvag,项目名称:routeops,代码行数:7,代码来源:rib.py


示例2: get_prefixes

 def get_prefixes(self, key):
     with lock():
         result = []
         for p in self.peer['prefixes']:
             if p['prefix'] == key:
                 result.append(p)
         return result
开发者ID:rafaelsilvag,项目名称:routeops,代码行数:7,代码来源:rib.py


示例3: delete

 def delete(self, key):
     with lock():
         for p in self.peer['prefixes']:
             if p['prefix'] == key:
                 self.peer['prefixes'].remove(p)
                 self.db['peers'].save(self.peer)
                 break
开发者ID:rafaelsilvag,项目名称:routeops,代码行数:7,代码来源:rib.py


示例4: get

 def get(self,key): 
     
     with lock():
         cursor = self.db.cursor()
         cursor.execute('''select * from ''' + self.name + ''' where prefix = ?''', (key,))
     
         return cursor.fetchone()
开发者ID:rbirkner,项目名称:sdx-ryu,代码行数:7,代码来源:rib.py


示例5: update

 def update(self,key,item,value):
     
     with lock():
         cursor = self.db.cursor()
     
         script = "update " + self.name + " set " + item + " = '" + value + "' where prefix = '" + key + "'"
     
         cursor.execute(script)
开发者ID:rbirkner,项目名称:sdx-ryu,代码行数:8,代码来源:rib.py


示例6: add_many

 def add_many(self,items):
     
     with lock():
         cursor = self.db.cursor()
     
         if (isinstance(items,list)):
             cursor.execute('''insert or replace into ''' + self.name + ''' (prefix, next_hop, origin, as_path, communities, med,
                     atomic_aggregate) values(?,?,?,?,?,?,?)''', items)
开发者ID:rbirkner,项目名称:sdx-ryu,代码行数:8,代码来源:rib.py


示例7: delete

 def delete(self,key):
     
     with lock():
         # TODO: Add more granularity in the delete process i.e., instead of just prefix, 
         # it should be based on a conjunction of other attributes too.
     
         cursor = self.db.cursor()
     
         cursor.execute('''delete from ''' + self.name + ''' where prefix = ?''', (key,))
开发者ID:rbirkner,项目名称:sdx-ryu,代码行数:9,代码来源:rib.py


示例8: update_neighbor

 def update_neighbor(self, key, item):
     with lock():
         if (isinstance(item, dict)):
             for p in self.peer['prefixes']:
                 if p['prefix'] == key and p['next_hop'] == item['next_hop']:
                     self.peer['prefixes'].remove(p)
                     break
             item['prefix'] = key
             self.peer['prefixes'].append(item)
             self.db['peers'].save(self.peer)
开发者ID:rafaelsilvag,项目名称:routeops,代码行数:10,代码来源:rib.py


示例9: filter

 def filter(self,item,value): 
         
     with lock():
         cursor = self.db.cursor()
     
         script = "select * from " + self.name + " where " + item + " = '" + value + "'"
     
         cursor.execute(script)
     
         return cursor.fetchall()
开发者ID:rbirkner,项目名称:sdx-ryu,代码行数:10,代码来源:rib.py


示例10: __init__

    def __init__(self, import_name, static_url_path=none,
                 static_folder='static', template_folder='templates',
                 instance_path=none, instance_relative_config=false):
        _packageboundobject.__init__(self, import_name,
                                     template_folder=template_folder)
        
        if static_url_path is not none:
            self.static_url_path = static_url_path
        if static_folder is not none:
            self.static_folder = static_folder
        if instance_path is none:
            instance_path = self.auto_find_instance_path()
        elif not os.path.isabs(instance_path):
            raise valueerror('if an instance path is provided it must be '
                             'absolute.  a relative path was given instead.')
        
        self.instance_path = instance_path
        
        self.config = self.make_config(instance_relative_config)
        
        self._logger = none
        self.logger_name = self.import_name

        self.view_functions = {}

        self.error_handler_spec = {none: self._error_handlers}

        self.url_build_error_handlers = []

        self.before_request_funcs = {}
        self.before_first_request_funcs = []
        self.after_request_funcs = {}
        self.teardown_request_funcs = {}
        self.teardown_appcontext_funcs = []
        
        self.url_value_preprocessors = {}
        self.url_default_functions = {}

        self.template_context_processors = {
            none: [_default_template_ctx_processor]
        }

        self.blueprints = {}

        self.extensions = {}

        self.url_map = map()

        self._got_first_request = false
        self._before_request_lock = lock()

        if self.has_static_folder:
            self.add_url_rule(self.static_url_path + '/<path:filename>',
                              endpoint='static',
                              view_func=self.send_static_file)
开发者ID:echhost,项目名称:flasker,代码行数:55,代码来源:app.py


示例11: update

 def update(self, item, value):
     with lock():
         if not self.peer['prefixes']:
             self.peer['prefixes'] = []
         for p in self.peer['prefixes']:
             if p['prefix'] == item:
                 self.peer['prefixes'].remove(p)
                 break
         value['prefix'] = item
         self.peer['prefixes'].append(value)
         self.db['peers'].save(self.peer)
开发者ID:rafaelsilvag,项目名称:routeops,代码行数:11,代码来源:rib.py


示例12: get_all

 def get_all(self,key=None): 
     
     with lock():    
         cursor = self.db.cursor()
     
         if (key is not None):
             cursor.execute('''select * from ''' + self.name + ''' where prefix = ?''', (key,))
         else:
             cursor.execute('''select * from ''' + self.name)
     
         return cursor.fetchall()
开发者ID:rbirkner,项目名称:sdx-ryu,代码行数:11,代码来源:rib.py


示例13: add

 def add(self, key, item):
     with lock():
         if not self.peer['prefixes']:
             self.peer['prefixes'] = []
         if (isinstance(item, dict)):
             for p in self.peer['prefixes']:
                 if p['prefix'] == key:
                     self.peer['prefixes'].remove(p)
                     break
             item['prefix'] = key
             self.peer['prefixes'].append(item)
             self.db['peers'].save(self.peer)
开发者ID:rafaelsilvag,项目名称:routeops,代码行数:12,代码来源:rib.py


示例14: add

 def add(self,key,item):
     
     with lock():
         cursor = self.db.cursor()
     
         if (isinstance(item,tuple) or isinstance(item,list)):
             cursor.execute('''insert or replace into ''' + self.name + ''' (prefix, next_hop, origin, as_path, communities, med,
                     atomic_aggregate) values(?,?,?,?,?,?,?)''', 
                     (key,item[0],item[1],item[2],item[3],item[4],item[5]))
         elif (isinstance(item,dict) or isinstance(item,sqlite3.Row)):
             cursor.execute('''insert or replace into ''' + self.name + ''' (prefix, next_hop, origin, as_path, communities, med,
                     atomic_aggregate) values(?,?,?,?,?,?,?)''', 
                     (key,item['next_hop'],item['origin'],item['as_path'],item['communities'],item['med'],item['atomic_aggregate']))
开发者ID:rbirkner,项目名称:sdx-ryu,代码行数:13,代码来源:rib.py


示例15: update_many

 def update_many(self,key,item):
     
     with lock():
         cursor = self.db.cursor()
     
         if (isinstance(item,tuple) or isinstance(item,list)):
             cursor.execute('''update ''' + self.name + ''' set next_hop = ?, origin = ?, as_path = ?,
                         communities = ?, med = ?, atomic_aggregate = ? where prefix = ?''',
                         (item[0],item[1],item[2],item[3],item[4],item[5],key))
         elif (isinstance(item,dict) or isinstance(item,sqlite3.Row)):
             cursor.execute('''update ''' + self.name + ''' set next_hop = ?, origin = ?, as_path = ?,
                         communities = ?, med = ?, atomic_aggregate = ? where prefix = ?''', 
                         (item['next_hop'],item['origin'],item['as_path'],item['communities'],item['med'],
                          item['atomic_aggregate'],key))
开发者ID:rbirkner,项目名称:sdx-ryu,代码行数:14,代码来源:rib.py


示例16: main

def main(num):
	global count, mutex
	thread = []

	count = 1
	#创建锁
	mutex = threading.lock()
	for x in xrange(0, num):
		threads.append(threading.Thread(target=thread_main, args=(10,)))
	#启动所有线程
	for t in threads:
		t.start()
	#主线程等待所有子线程推出
	for t in threads:
		t.join()
开发者ID:heyuhang,项目名称:python,代码行数:15,代码来源:threading1.py


示例17: __init__

 def __init__(self,ip,name):
     
     with lock():
         # Create a database in RAM
         self.db = sqlite3.connect('/home/vagrant/sdx-ryu/xrs/ribs/'+ip+'.db',check_same_thread=False)
         self.db.row_factory = sqlite3.Row
         self.name = name
     
         # Get a cursor object
         cursor = self.db.cursor()
         cursor.execute('''
                     create table if not exists '''+self.name+''' (prefix text, next_hop text,
                            origin text, as_path text, communities text, med integer, atomic_aggregate boolean)
         ''')
    
         self.db.commit()
开发者ID:alexdouckas,项目名称:sdx-ryu,代码行数:16,代码来源:rib.py


示例18: __init__

 def __init__(self,ip,name):
     
     with lock():
         # Create a database in RAM
         base_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)),"ribs"))
         self.db = sqlite3.connect(base_path+'/'+ip+'.db',check_same_thread=False)
         self.db.row_factory = sqlite3.Row
         self.name = name
     
         # Get a cursor object
         cursor = self.db.cursor()
         cursor.execute('''
                     create table if not exists '''+self.name+''' (prefix text, next_hop text,
                            origin text, as_path text, communities text, med integer, atomic_aggregate boolean, primary key (prefix))
         ''')
    
         self.db.commit()
开发者ID:rbirkner,项目名称:sdx-ryu,代码行数:17,代码来源:rib.py


示例19: flush

	def flush(self):
		lock=threading.lock()
		while True:
			lock.acquire()
			try:
				proxy=self.curse.next()
				proxies = {"http": 'http://'+proxy}
			except StopIteration:
				print 'not available'
				break
			try:
				r=requests.get('http://www.baidu.com',proxies=proxies,timeout=5)
			except:
				self.ips.remove(proxy)
				print proxy+' Can`t connect!'+' No.'+str(self.content.index(proxy))
				continue
			print r.content
		self.write(self.ips)
开发者ID:ZWY188551,项目名称:spider,代码行数:18,代码来源:proxy.py


示例20:

import threading
message_lock = threading.lock()

with message_lock:
    messages.add(newmessage)
开发者ID:tzu-yen,项目名称:PythonPractice,代码行数:5,代码来源:mutexlock.py



注:本文中的threading.lock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python threading.main_thread函数代码示例发布时间:2022-05-27
下一篇:
Python threading.local函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap