Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Merge 5940ff7 into 35e3868
Browse files Browse the repository at this point in the history
  • Loading branch information
rmotitsuki committed Apr 13, 2021
2 parents 35e3868 + 5940ff7 commit 23c1237
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions kytos/core/kytosd.py
Expand Up @@ -5,6 +5,7 @@
import os
import signal
from concurrent.futures import ThreadPoolExecutor
from contextlib import suppress
from pathlib import Path

import daemon
Expand Down Expand Up @@ -115,10 +116,11 @@ def stop_controller(controller):
"""Stop the controller before quitting."""
loop = asyncio.get_event_loop()

# If stop() hangs, old ctrl+c behaviour will be restored
loop.remove_signal_handler(signal.SIGINT)
loop.remove_signal_handler(signal.SIGTERM)

if loop:
# If stop() hangs, old ctrl+c behaviour will be restored
loop.remove_signal_handler(signal.SIGINT)
loop.remove_signal_handler(signal.SIGTERM)

# disable_threadpool_exit()

controller.log.info("Stopping Kytos controller...")
Expand Down Expand Up @@ -155,4 +157,12 @@ async def start_shell_async():
controller.log.error(exc)
controller.log.info("Shutting down Kytos...")
finally:
pending = asyncio.Task.all_tasks()
for task in pending:
cancelled = task.cancel()
# Now we should await task to execute it's cancellation.
# Cancelled task raises asyncio.CancelledError that we suppress.
with suppress(asyncio.CancelledError):
loop.run_until_complete(task)

loop.close()

0 comments on commit 23c1237

Please sign in to comment.