Skip to content

Commit

Permalink
Cleanup: Apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Feb 20, 2024
1 parent 02e85c7 commit 1ce28b9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/aleph/vm/pool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import asyncio
import json
import logging
Expand Down Expand Up @@ -128,11 +129,7 @@ async def create_a_vm(
self.forget_vm(vm_hash)
raise

async def forget_on_stop(stop_event: asyncio.Event):
await stop_event.wait()
self.forget_vm(vm_hash)

_ = asyncio.create_task(forget_on_stop(stop_event=execution.stop_event))
self._schedule_forget_on_stop(execution)

return execution

Expand Down Expand Up @@ -202,6 +199,14 @@ def forget_vm(self, vm_hash: ItemHash) -> None:
except KeyError:
pass

def _schedule_forget_on_stop(self, execution: VmExecution):
"""Create a task that will remove the VM from the pool after it stops."""
async def forget_on_stop(stop_event: asyncio.Event):
await stop_event.wait()
self.forget_vm(execution.vm_hash)

_ = asyncio.create_task(forget_on_stop(stop_event=execution.stop_event))

async def _load_persistent_executions(self):
"""Load persistent executions from the database."""
saved_executions = await get_execution_records()
Expand All @@ -224,12 +229,7 @@ async def _load_persistent_executions(self):
persistent=saved_execution.persistent,
)

# Ensure the VM is forgotten from the pool if it is stopped.
async def forget_on_stop(stop_event: asyncio.Event):
await stop_event.wait()
self.forget_vm(vm_hash)

_ = asyncio.create_task(forget_on_stop(stop_event=execution.stop_event))
self._schedule_forget_on_stop(execution)

if execution.is_running:
# TODO: Improve the way that we re-create running execution
Expand Down

0 comments on commit 1ce28b9

Please sign in to comment.