diff --git a/lona/view_runtime.py b/lona/view_runtime.py index e03d5177..231fd46c 100644 --- a/lona/view_runtime.py +++ b/lona/view_runtime.py @@ -120,6 +120,14 @@ def __init__( self.stop_reason = None self.is_daemon = False + # TODO: remove in 2.0 + # compatibility for older Lona application code + self.stop_daemon_when_view_finishes = getattr( + self.view, + 'STOP_DAEMON_WHEN_VIEW_FINISHES', + self.server.settings.STOP_DAEMON_WHEN_VIEW_FINISHES, + ) + self.view_runtime_id = generate_unique_id(name_space='view_runtimes') self.state = VIEW_RUNTIME_STATE.NOT_STARTED self.thread_ident = None @@ -474,7 +482,10 @@ def remove_connection(self, connection, window_id=None): # if the last connection gets closed and the view should # not continue running in background, it gets stopped - if not self.connections and not self.is_daemon: + if (not self.connections and + self.stop_daemon_when_view_finishes and + not self.is_daemon): + self.stop() # lona messages ########################################################### diff --git a/lona/view_runtime_controller.py b/lona/view_runtime_controller.py index 3df319b1..e9fc2e79 100644 --- a/lona/view_runtime_controller.py +++ b/lona/view_runtime_controller.py @@ -48,15 +48,9 @@ def get_running_view_runtime(self, user, route, match_info): continue - # TODO: remove in 2.0 - # compatibility for older Lona application code - stop_daemon_when_view_finishes = getattr( - view_runtime.view, - 'STOP_DAEMON_WHEN_VIEW_FINISHES', - self.server.settings.STOP_DAEMON_WHEN_VIEW_FINISHES, - ) + if (view_runtime.stop_daemon_when_view_finishes and + view_runtime.is_stopped): - if stop_daemon_when_view_finishes and view_runtime.is_stopped: continue return view_runtime