Skip to content

Commit

Permalink
Remove python-daemon dependency
Browse files Browse the repository at this point in the history
remove python-daemon since it uses unsupported dependency 'lockfile'

Fixes: #379

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
  • Loading branch information
Akasurde committed May 4, 2022
1 parent 6a53a5d commit 2b43901
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
5 changes: 2 additions & 3 deletions ansible_runner/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from ansible_runner import cleanup
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.locks import TimeoutProcessLock
from ansible_runner.runner import Runner
from ansible_runner.exceptions import AnsibleRunnerException

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

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

Expand Down
11 changes: 7 additions & 4 deletions 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 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()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pexpect>=4.5
packaging
python-daemon
fasteners>=0.16
pyyaml
six
2 changes: 1 addition & 1 deletion tools/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ pypsrp[kerberos,credssp]
pywinrm[kerberos,credssp]
toml
pexpect>=4.5
python-daemon
fasteners>=0.16
pyyaml
six

0 comments on commit 2b43901

Please sign in to comment.