Skip to content

Commit

Permalink
Don't spew "Aborted!" to the command-line when the Daemon is cleanly …
Browse files Browse the repository at this point in the history
…interrupted (#11739)

Right now whenever you CTRL-C the daemon (or `dagster dev` terminates
the daemon) we hit some generic click logic that prints out a scary
"Aborted!" message, even though its the expected way to end the process.
Instead of
bubbling the interrupt up to click, catch it in the CLI command and exit
cleanly.

uvicorn in dagit has similar logic that causes dagit to exit with return
code 0 when an interrupt happens.

Test Plan:
Run daemon locally, CTRL-C, no more scary "Aborted!" message, same with
dagster dev
  • Loading branch information
gibsondan committed Jan 18, 2023
1 parent f232973 commit f6e47d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 8 additions & 5 deletions python_modules/dagster/dagster/_daemon/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ def _get_heartbeat_tolerance():
)
@workspace_target_argument
def run_command(code_server_log_level, instance_ref, **kwargs):
with capture_interrupts():
with DagsterInstance.from_ref(
deserialize_as(instance_ref, InstanceRef)
) if instance_ref else DagsterInstance.get() as instance:
_daemon_run_command(instance, code_server_log_level, kwargs)
try:
with capture_interrupts():
with DagsterInstance.from_ref(
deserialize_as(instance_ref, InstanceRef)
) if instance_ref else DagsterInstance.get() as instance:
_daemon_run_command(instance, code_server_log_level, kwargs)
except KeyboardInterrupt:
return # Exit cleanly on interrupt


@telemetry_wrapper(metadata={"DAEMON_SESSION_ID": get_telemetry_daemon_session_id()})
Expand Down
9 changes: 8 additions & 1 deletion python_modules/dagster/dagster/_daemon/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,14 @@ def check_daemon_loop(self):
last_heartbeat_check_time = time.time()

def __exit__(self, exception_type, exception_value, traceback):
self._logger.info("Shutting down daemon threads...")
if isinstance(exception_value, KeyboardInterrupt):
self._logger.info("Received interrupt, shutting down daemon threads...")
elif exception_type:
self._logger.warning(
f"Shutting down daemon threads due to {exception_type.__name__}..."
)
else:
self._logger.info("Shutting down daemon threads...")
self._daemon_shutdown_event.set()
for daemon_type, thread in self._daemon_threads.items():
if thread.is_alive():
Expand Down

0 comments on commit f6e47d8

Please sign in to comment.