libkas: Do not close event loop after each command

Rather close the loop when terminating the kas process.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2017-06-28 12:43:52 +02:00 committed by Daniel Wagner
parent 34cf6900ca
commit 94555bb892
2 changed files with 3 additions and 7 deletions

View File

@ -77,8 +77,9 @@ def create_logger():
def _atexit_handler(loop):
"""
Terminate the whole process group
Close event loop and terminate the whole process group
"""
asyncio.get_event_loop().close()
os.killpg(os.getpid(), signal.SIGTERM)

View File

@ -125,16 +125,11 @@ def run_cmd(cmd, cwd, env=None, fail=True, shell=False, liveupdate=True):
logging.info('%s$ %s', cwd, cmdstr)
logo = LogOutput(liveupdate)
if asyncio.get_event_loop().is_closed():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
else:
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop()
retc = loop.run_until_complete(
_stream_subprocess(cmd, cwd, env, shell,
logo.log_stdout, logo.log_stderr))
loop.close()
if retc and fail:
msg = 'Command "{cwd}$ {cmd}" failed\n'.format(cwd=cwd, cmd=cmdstr)