def _try_lock():
"""Check and create lock file - prevent running application twice.
Return lock file handler.
"""
lock_file_path = _find_config_file("app.lock", False)
_check_dir_for_file(lock_file_path)
try:
if fcntl is not None:
lock_file = open(lock_file_path, "w")
fcntl.lockf(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
else:
if os.path.isfile(lock_file_path):
_LOG.error("another instance detected (lock file exists) "
"- exiting")
return None
lock_file = open(lock_file_path, "w")
return lock_file
except IOError as err:
import errno
if err.errno == errno.EAGAIN:
_LOG.error("another instance detected - exiting")
else:
_LOG.exception("locking failed: %s", err)
return None
评论列表
文章目录