本文整理汇总了Python中lock.Lock.has_lock方法的典型用法代码示例。如果您正苦于以下问题:Python Lock.has_lock方法的具体用法?Python Lock.has_lock怎么用?Python Lock.has_lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lock.Lock
的用法示例。
在下文中一共展示了Lock.has_lock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_repositories
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import has_lock [as 别名]
def process_repositories(self, repo_configs, ref, action, request_body):
import os
import time
import logging
from wrappers import GitWrapper
from lock import Lock
import json
logger = logging.getLogger()
data = json.loads(request_body)
# Process each matching repository
for repo_config in repo_configs:
try:
# Verify that all filters matches the request (if any filters are specified)
if 'filters' in repo_config:
# at least one filter must match
for filter in repo_config['filters']:
# all options specified in the filter must match
for filter_key, filter_value in filter.iteritems():
# support for earlier version so it's non-breaking functionality
if filter_key == 'action' and filter_value == action:
continue
if filter_key not in data or filter_value != data[filter_key]:
raise FilterMatchError()
except FilterMatchError as e:
# Filter does not match, do not process this repo config
continue
# In case there is no path configured for the repository, no pull will
# be made.
if not 'path' in repo_config:
GitWrapper.deploy(repo_config)
continue
running_lock = Lock(os.path.join(repo_config['path'], 'status_running'))
waiting_lock = Lock(os.path.join(repo_config['path'], 'status_waiting'))
try:
# Attempt to obtain the status_running lock
while not running_lock.obtain():
# If we're unable, try once to obtain the status_waiting lock
if not waiting_lock.has_lock() and not waiting_lock.obtain():
logger.error("Unable to obtain the status_running lock nor the status_waiting lock. Another process is " +
"already waiting, so we'll ignore the request.")
# If we're unable to obtain the waiting lock, ignore the request
break
# Keep on attempting to obtain the status_running lock until we succeed
time.sleep(5)
n = 4
while 0 < n and 0 != GitWrapper.pull(repo_config):
n -= 1
if 0 < n:
GitWrapper.deploy(repo_config)
except Exception as e:
logger.error('Error during \'pull\' or \'deploy\' operation on path: %s' % repo_config['path'])
logger.error(e)
finally:
# Release the lock if it's ours
if running_lock.has_lock():
running_lock.release()
# Release the lock if it's ours
if waiting_lock.has_lock():
waiting_lock.release()
示例2: process_repositories
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import has_lock [as 别名]
def process_repositories(self, repo_configs, ref, action, request_body):
"""Verify that the suggested repositories has matching settings and
issue git pull and/or deploy commands."""
import os
import time
import logging
from wrappers import GitWrapper
from lock import Lock
import json
logger = logging.getLogger()
data = json.loads(request_body)
result = []
# Process each matching repository
for repo_config in repo_configs:
repo_result = {}
try:
# Verify that all filters matches the request (if any filters are specified)
if 'filters' in repo_config:
# At least one filter must match
for filter in repo_config['filters']:
# All options specified in the filter must match
for filter_key, filter_value in filter.iteritems():
# Ignore filters with value None (let them pass)
if filter_value == None:
continue
# Support for earlier version so it's non-breaking functionality
if filter_key == 'action' and filter_value == action:
continue
# Interpret dots in filter name as path notations
node_value = data
for node_key in filter_key.split('.'):
# If the path is not valid the filter does not match
if not node_key in node_value:
logger.info("Filter '%s'' does not match since the path is invalid" % (filter_key))
raise FilterMatchError()
node_value = node_value[node_key]
if filter_value == node_value:
continue
# If the filter value is set to True. the filter
# will pass regardless of the actual value
if filter_value == True:
continue
logger.info("Filter '%s'' does not match ('%s' != '%s')" % (filter_key, filter_value, (str(node_value)[:75] + '..') if len(str(node_value)) > 75 else str(node_value)))
raise FilterMatchError()
except FilterMatchError as e:
# Filter does not match, do not process this repo config
continue
# In case there is no path configured for the repository, no pull will
# be made.
if not 'path' in repo_config:
res = GitWrapper.deploy(repo_config)
repo_result['deploy'] = res
result.append(repo_result)
continue
running_lock = Lock(os.path.join(repo_config['path'], 'status_running'))
waiting_lock = Lock(os.path.join(repo_config['path'], 'status_waiting'))
try:
# Attempt to obtain the status_running lock
while not running_lock.obtain():
# If we're unable, try once to obtain the status_waiting lock
if not waiting_lock.has_lock() and not waiting_lock.obtain():
logger.error("Unable to obtain the status_running lock nor the status_waiting lock. Another process is " +
"already waiting, so we'll ignore the request.")
# If we're unable to obtain the waiting lock, ignore the request
break
# Keep on attempting to obtain the status_running lock until we succeed
time.sleep(5)
n = 4
res = None
while n > 0:
# Attempt to pull up a maximum of 4 times
print repo_config
if not repo_config.get('branch'):
#.........这里部分代码省略.........