Skip to content

Commit

Permalink
Fix: Changed threads implementation by asyncio implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nesitor authored and hoh committed Mar 21, 2024
1 parent 73e51ab commit ab29137
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/aleph/vm/orchestrator/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def run():
engine = setup_engine()
asyncio.run(create_tables(engine))

pool = VmPool()
loop = asyncio.new_event_loop()
pool = VmPool(loop)
pool.setup()

hostname = settings.DOMAIN_NAME
Expand Down
12 changes: 6 additions & 6 deletions src/aleph/vm/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import json
import logging
import threading
from collections.abc import Iterable
from datetime import datetime, timezone
from typing import Optional
Expand Down Expand Up @@ -44,12 +43,14 @@ class VmPool:
network: Optional[Network]
snapshot_manager: Optional[SnapshotManager] = None
systemd_manager: SystemDManager
creation_lock: threading.Lock
creation_lock: asyncio.Lock

def __init__(self):
def __init__(self, loop: asyncio.AbstractEventLoop):
self.counter = settings.START_ID_INDEX
self.executions = {}
self.creation_lock = threading.Lock()

asyncio.set_event_loop(loop)
self.creation_lock = asyncio.Lock()

self.network = (
Network(
Expand Down Expand Up @@ -89,8 +90,7 @@ async def create_a_vm(
self, vm_hash: ItemHash, message: ExecutableContent, original: ExecutableContent, persistent: bool
) -> VmExecution:
"""Create a new Aleph Firecracker VM from an Aleph function message."""

with self.creation_lock:
async with self.creation_lock:
# Check if an execution is already present for this VM, then return it.
# Do not `await` in this section.
current_execution = self.get_running_vm(vm_hash)
Expand Down

0 comments on commit ab29137

Please sign in to comment.