Skip to content

Commit 30b8d76

Browse files
committed
Remove python-daemon dependency
remove python-daemon since it uses unsupported dependency 'lockfile' Fixes: #379 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
1 parent 82a231d commit 30b8d76

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77
[[tool.mypy.overrides]]
88
module = [
99
"ansible.*",
10-
"daemon.*",
10+
"fasteners.*",
1111
"pexpect",
1212
]
1313
ignore_missing_imports = true

src/ansible_runner/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
from contextlib import contextmanager
3535
from uuid import uuid4
3636

37-
import daemon
38-
from daemon.pidfile import TimeoutPIDLockFile
3937
from yaml import safe_dump, safe_load
4038

4139
from ansible_runner import run
@@ -44,6 +42,7 @@
4442
from ansible_runner.utils import dump_artifact, Bunch, register_for_cleanup
4543
from ansible_runner.utils.capacity import get_cpu_count, get_mem_in_bytes, ensure_uuid
4644
from ansible_runner.utils.importlib_compat import importlib_metadata
45+
from ansible_runner.utils.locks import TimeoutProcessLock
4746
from ansible_runner.runner import Runner
4847
from ansible_runner.exceptions import AnsibleRunnerException
4948

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

826825
if vargs.get('command') == 'start':
827-
context = daemon.DaemonContext(pidfile=TimeoutPIDLockFile(pidfile))
826+
context = TimeoutProcessLock(pidfile).locked(5)
828827
else:
829828
context = threading.Lock()
830829

src/ansible_runner/exceptions.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
21
class AnsibleRunnerException(Exception):
3-
""" Generic Runner Error """
2+
"""Generic Runner Error"""
43

54

65
class ConfigurationError(AnsibleRunnerException):
7-
""" Misconfiguration of Runner """
6+
"""Misconfiguration of Runner"""
87

98

109
class CallbackError(AnsibleRunnerException):
11-
""" Exception occurred in Callback """
10+
"""Exception occurred in Callback"""
11+
12+
13+
class ProcessLockException(Exception):
14+
"""Exception occurred in Locking process using fasteners"""

src/ansible_runner/utils/locks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from contextlib import contextmanager
2+
from fasteners import InterProcessLock
3+
from ansible_runner.exceptions import ProcessLockException
4+
5+
6+
class TimeoutProcessLock(InterProcessLock):
7+
8+
@contextmanager
9+
def locked(self, timeout):
10+
ok = self.acquire(timeout=timeout)
11+
if not ok:
12+
raise ProcessLockException()
13+
try:
14+
yield
15+
finally:
16+
self.release()

0 commit comments

Comments
 (0)