本文整理汇总了Python中threading.lock函数的典型用法代码示例。如果您正苦于以下问题:Python lock函数的具体用法?Python lock怎么用?Python lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例4: get
def get(self,key):
with lock():
cursor = self.db.cursor()
cursor.execute('''select * from ''' + self.name + ''' where prefix = ?''', (key,))
return cursor.fetchone()
示例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)
示例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)
示例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,))
示例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)
示例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()
示例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)
示例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)
示例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()
示例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)
示例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']))
示例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))