diff --git a/src/aleph/vm/models.py b/src/aleph/vm/models.py index 6630b35bc..bb443bca3 100644 --- a/src/aleph/vm/models.py +++ b/src/aleph/vm/models.py @@ -90,6 +90,10 @@ def is_running(self): else self.systemd_manager.is_service_active(self.controller_service) ) + @property + def is_stopping(self) -> bool: + return bool(self.times.stopping_at and not self.times.stopped_at) + @property def is_program(self): return isinstance(self.message, ProgramContent) diff --git a/src/aleph/vm/pool.py b/src/aleph/vm/pool.py index 0c1673cee..a647718bd 100644 --- a/src/aleph/vm/pool.py +++ b/src/aleph/vm/pool.py @@ -164,7 +164,7 @@ def get_unique_vm_id(self) -> int: async def get_running_vm(self, vm_hash: ItemHash) -> Optional[VmExecution]: """Return a running VM or None. Disables the VM expiration task.""" execution = self.executions.get(vm_hash) - if execution and execution.is_running: + if execution and execution.is_running and not execution.is_stopping: execution.cancel_expiration() return execution else: