Skip to content

Commit ab29137

Browse files
nesitorhoh
authored andcommitted
Fix: Changed threads implementation by asyncio implementation.
1 parent 73e51ab commit ab29137

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/aleph/vm/orchestrator/supervisor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def run():
134134
engine = setup_engine()
135135
asyncio.run(create_tables(engine))
136136

137-
pool = VmPool()
137+
loop = asyncio.new_event_loop()
138+
pool = VmPool(loop)
138139
pool.setup()
139140

140141
hostname = settings.DOMAIN_NAME

src/aleph/vm/pool.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import asyncio
44
import json
55
import logging
6-
import threading
76
from collections.abc import Iterable
87
from datetime import datetime, timezone
98
from typing import Optional
@@ -44,12 +43,14 @@ class VmPool:
4443
network: Optional[Network]
4544
snapshot_manager: Optional[SnapshotManager] = None
4645
systemd_manager: SystemDManager
47-
creation_lock: threading.Lock
46+
creation_lock: asyncio.Lock
4847

49-
def __init__(self):
48+
def __init__(self, loop: asyncio.AbstractEventLoop):
5049
self.counter = settings.START_ID_INDEX
5150
self.executions = {}
52-
self.creation_lock = threading.Lock()
51+
52+
asyncio.set_event_loop(loop)
53+
self.creation_lock = asyncio.Lock()
5354

5455
self.network = (
5556
Network(
@@ -89,8 +90,7 @@ async def create_a_vm(
8990
self, vm_hash: ItemHash, message: ExecutableContent, original: ExecutableContent, persistent: bool
9091
) -> VmExecution:
9192
"""Create a new Aleph Firecracker VM from an Aleph function message."""
92-
93-
with self.creation_lock:
93+
async with self.creation_lock:
9494
# Check if an execution is already present for this VM, then return it.
9595
# Do not `await` in this section.
9696
current_execution = self.get_running_vm(vm_hash)

0 commit comments

Comments
 (0)