-def _already_running():
- """If a pidfile has been configured and that pidfile already exists and is
- locked by a running process, returns True. Otherwise, returns False."""
- if _pidfile is not None:
- try:
- file = open(_pidfile, "r+")
- try:
- try:
- fcntl.lockf(file, fcntl.LOCK_EX | fcntl.LOCK_NB)
- except IOError, e:
- if e.errno in [errno.EACCES, errno.EAGAIN]:
- return True
- logging.error("error locking %s (%s)"
- % (_pidfile, os.strerror(e.errno)))
- return False
- finally:
- # This releases the lock, which we don't really want.
- file.close()
- except IOError, e:
- if e.errno == errno.ENOENT:
- return False
- logging.error("error opening %s (%s)"
- % (_pidfile, os.strerror(e.errno)))
- return False
-