|
3 | 3 | import asyncio
|
4 | 4 | import json
|
5 | 5 | import logging
|
6 |
| -import threading |
7 | 6 | from collections.abc import Iterable
|
8 | 7 | from datetime import datetime, timezone
|
9 | 8 | from typing import Optional
|
@@ -44,12 +43,14 @@ class VmPool:
|
44 | 43 | network: Optional[Network]
|
45 | 44 | snapshot_manager: Optional[SnapshotManager] = None
|
46 | 45 | systemd_manager: SystemDManager
|
47 |
| - creation_lock: threading.Lock |
| 46 | + creation_lock: asyncio.Lock |
48 | 47 |
|
49 |
| - def __init__(self): |
| 48 | + def __init__(self, loop: asyncio.AbstractEventLoop): |
50 | 49 | self.counter = settings.START_ID_INDEX
|
51 | 50 | self.executions = {}
|
52 |
| - self.creation_lock = threading.Lock() |
| 51 | + |
| 52 | + asyncio.set_event_loop(loop) |
| 53 | + self.creation_lock = asyncio.Lock() |
53 | 54 |
|
54 | 55 | self.network = (
|
55 | 56 | Network(
|
@@ -89,8 +90,7 @@ async def create_a_vm(
|
89 | 90 | self, vm_hash: ItemHash, message: ExecutableContent, original: ExecutableContent, persistent: bool
|
90 | 91 | ) -> VmExecution:
|
91 | 92 | """Create a new Aleph Firecracker VM from an Aleph function message."""
|
92 |
| - |
93 |
| - with self.creation_lock: |
| 93 | + async with self.creation_lock: |
94 | 94 | # Check if an execution is already present for this VM, then return it.
|
95 | 95 | # Do not `await` in this section.
|
96 | 96 | current_execution = self.get_running_vm(vm_hash)
|
|
0 commit comments