Skip to content

Commit

Permalink
Merge branch 'master' into get_ips_per_net
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaniv Kaul authored Nov 19, 2017
2 parents b96c0a5 + 9fd0e34 commit 6692139
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/Templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Available templates
+------------------+--------------+
| el7.3-base | CentOS 7.3 |
+------------------+--------------+
| el7.4-base | CentOS 7.4 |
+------------------+--------------+
| fc23-base | Fedora 23 |
+------------------+--------------+
| fc24-base | Fedora 24 |
Expand Down
24 changes: 24 additions & 0 deletions lago/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import sys
from textwrap import dedent
import warnings
from signal import signal, SIGTERM, SIGHUP

import lago
import lago.plugins
Expand Down Expand Up @@ -899,7 +900,30 @@ def create_parser(cli_plugins, out_plugins):
return parser


def exit_handler(signum, frame):
"""
Catch SIGTERM and SIGHUP and call "sys.exit" which raises
"SystemExit" exception.
This will trigger all the cleanup code defined in ContextManagers
and "finally" statements.
For more details about the arguments see "signal" documentation.
Args:
signum(int): The signal's number
frame(frame): The current stack frame, can be None
"""

LOGGER.debug('signal {} was caught'.format(signum))
sys.exit(128 + signum)


def main():

# Trigger cleanup on SIGTERM and SIGHUP
signal(SIGTERM, exit_handler)
signal(SIGHUP, exit_handler)

cli_plugins = lago.plugins.load_plugins(
lago.plugins.PLUGIN_ENTRY_POINTS['cli']
)
Expand Down
6 changes: 5 additions & 1 deletion lago/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def __enter__(self):
with ExceptionTimer(timeout=self.timeout):
LOGGER.debug('Acquiring lock for {}'.format(self.path))
self.lock.acquire()
LOGGER.debug('Holding the lock for {}'.format(self.path))
except TimerException:
raise TimerException(
'Unable to acquire lock for %s in %s secs',
Expand All @@ -398,7 +399,10 @@ def __enter__(self):
)

def __exit__(self, *_):
self.lock.release()
if self.lock.is_locked():
LOGGER.debug('Trying to release lock {}'.format(self.path))
self.lock.release()
LOGGER.debug('Lock {} was released')


def read_nonblocking(file_descriptor):
Expand Down

0 comments on commit 6692139

Please sign in to comment.