Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
[[tool.mypy.overrides]]
module = [
"ansible.*",
"daemon.*",
"fasteners.*",
"pexpect",
]
ignore_missing_imports = true
Expand Down
5 changes: 2 additions & 3 deletions src/ansible_runner/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
from contextlib import contextmanager
from uuid import uuid4

import daemon
from daemon.pidfile import TimeoutPIDLockFile
from yaml import safe_dump, safe_load

from ansible_runner import run
Expand All @@ -44,6 +42,7 @@
from ansible_runner.utils import dump_artifact, Bunch, register_for_cleanup
from ansible_runner.utils.capacity import get_cpu_count, get_mem_in_bytes, ensure_uuid
from ansible_runner.utils.importlib_compat import importlib_metadata
from ansible_runner.utils.locks import TimeoutProcessLock
from ansible_runner.runner import Runner
from ansible_runner.exceptions import AnsibleRunnerException

Expand Down Expand Up @@ -824,7 +823,7 @@ def main(sys_args=None):
if vargs.get('command') in ('start', 'run', 'transmit', 'worker', 'process'):

if vargs.get('command') == 'start':
context = daemon.DaemonContext(pidfile=TimeoutPIDLockFile(pidfile))
context = TimeoutProcessLock(pidfile).locked(5)
else:
context = threading.Lock()

Expand Down
11 changes: 7 additions & 4 deletions src/ansible_runner/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

class AnsibleRunnerException(Exception):
""" Generic Runner Error """
"""Generic Runner Error"""


class ConfigurationError(AnsibleRunnerException):
""" Misconfiguration of Runner """
"""Misconfiguration of Runner"""


class CallbackError(AnsibleRunnerException):
""" Exception occurred in Callback """
"""Exception occurred in Callback"""


class ProcessLockException(Exception):
"""Exception occurred in Locking process using fasteners"""
16 changes: 16 additions & 0 deletions src/ansible_runner/utils/locks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from contextlib import contextmanager
from fasteners import InterProcessLock
from ansible_runner.exceptions import ProcessLockException


class TimeoutProcessLock(InterProcessLock):

@contextmanager
def locked(self, timeout):
ok = self.acquire(timeout=timeout)
if not ok:
raise ProcessLockException()
try:
yield
finally:
self.release()