Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error properly on startup #8121

Merged
merged 4 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 12 additions & 10 deletions kolibri/utils/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,14 @@ def SERVING(self, port):
register_zeroconf_service(port=port or self.port)

def STOP(self):
from kolibri.core.tasks.main import scheduler

scheduler.shutdown_scheduler()
if self.workers is not None:
for worker in self.workers:
worker.shutdown()
from kolibri.core.discovery.utils.network.search import (
unregister_zeroconf_service,
)

unregister_zeroconf_service()
from kolibri.core.tasks.main import scheduler

scheduler.shutdown_scheduler()

if self.workers is not None:
for worker in self.workers:
Expand Down Expand Up @@ -324,7 +321,7 @@ def __init__(self, bus, port, zip_port, pid_file=PID_FILE):
handler.priority = 10
self.bus.subscribe(bus_status, handler)

def set_pid_file(self, status):
def set_pid_file(self, status, *args):
"""
Writes a PID file in the format Kolibri parses

Expand Down Expand Up @@ -386,9 +383,9 @@ def __init__(self, bus):

self.handlers.update(
{
"SIGINT": self.handle_SIGTERM,
"CTRL_C_EVENT": self.handle_SIGTERM,
"CTRL_BREAK_EVENT": self.handle_SIGTERM,
"SIGINT": self.handle_SIGINT,
"CTRL_C_EVENT": self.handle_SIGINT,
"CTRL_BREAK_EVENT": self.handle_SIGINT,
}
)

Expand All @@ -405,6 +402,11 @@ def subscribe(self):
def ENTER(self):
self.process_pid = os.getpid()

def handle_SIGINT(self):
"""Transition to the EXITED state."""
self.bus.log("Keyboard interrupt caught. Exiting.")
self.bus.transition("EXITED")


class ProcessControlPlugin(Monitor):
def __init__(self, bus):
Expand Down
3 changes: 1 addition & 2 deletions kolibri/utils/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ def test_services_shutdown_on_stop(self, unregister_zeroconf_service):

# Do we shutdown workers correctly?
for mock_worker in services_plugin.workers:
assert mock_worker.shutdown.call_count == 2
assert mock_worker.shutdown.call_count == 1
assert mock_worker.mock_calls == [
mock.call.shutdown(),
mock.call.shutdown(wait=True),
]

Expand Down