diff --git a/src/aleph/vm/orchestrator/cli.py b/src/aleph/vm/orchestrator/cli.py index 22bd44147..65b290ba2 100644 --- a/src/aleph/vm/orchestrator/cli.py +++ b/src/aleph/vm/orchestrator/cli.py @@ -17,6 +17,7 @@ from sqlalchemy.ext.asyncio import create_async_engine from aleph.vm.conf import ALLOW_DEVELOPER_SSH_KEYS, make_db_url, settings +from aleph.vm.models import VmExecution from aleph.vm.pool import VmPool from aleph.vm.version import get_version_from_apt, get_version_from_git @@ -187,7 +188,8 @@ async def fake_read() -> bytes: bench: list[float] = [] - pool = VmPool() + loop = asyncio.get_event_loop() + pool = VmPool(loop) pool.setup() # Does not make sense in benchmarks @@ -236,25 +238,24 @@ async def fake_read() -> bytes: print("Event result", result) -async def start_instance(item_hash: ItemHash) -> None: +async def start_instance(item_hash: ItemHash, pubsub: Optional[PubSub], pool) -> VmExecution: """Run an instance from an InstanceMessage.""" - pool = VmPool() + return await start_persistent_vm(item_hash, pubsub, pool) + +async def run_instances(instances: list[ItemHash]) -> None: + """Run instances from a list of message identifiers.""" + logger.info(f"Instances to run: {instances}") + loop = asyncio.get_event_loop() + pool = VmPool(loop) # The main program uses a singleton pubsub instance in order to watch for updates. # We create another instance here since that singleton is not initialized yet. # Watching for updates on this instance will therefore not work. pubsub: Optional[PubSub] = None - await start_persistent_vm(item_hash, pubsub, pool) - - -async def run_instances(instances: list[ItemHash]) -> None: - """Run instances from a list of message identifiers.""" - logger.info(f"Instances to run: {instances}") + await asyncio.gather(*[start_instance(instance_id, pubsub, pool) for instance_id in instances]) - await asyncio.gather(*[start_instance(item_hash=instance_id) for instance_id in instances]) await asyncio.Event().wait() # wait forever - # TODO : should we really wait forever? @contextlib.contextmanager