Skip to content

Commit

Permalink
Fix: AttributeError: 'MicroVM' object has no attribute 'send_shutdown…
Browse files Browse the repository at this point in the history
…_message' (#653)

* Fix: AttributeError: 'MicroVM' object has no attribute 'send_shutdown_message'

Error reported on #652


Co-authored-by: Olivier Le Thanh Duong <[email protected]>
  • Loading branch information
hoh and olethanh authored Jul 5, 2024
1 parent 1fedcd7 commit a3c5a8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/aleph/vm/controllers/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ async def execute_persistent_vm(config: Configuration):
async def handle_persistent_vm(config: Configuration, execution: Union[MicroVM, QemuVM], process: Process):
# Catch the terminating signal and send a proper message to the vm to stop it so it close files properly
loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGTERM, execution.send_shutdown_message)

def callback():
"""Callback for the signal handler to stop the VM and cleanup properly on SIGTERM."""
loop.create_task(execution.teardown())

loop.add_signal_handler(signal.SIGTERM, callback)

await process.wait()
logger.info(f"Process terminated with {process.returncode}")
Expand Down
4 changes: 4 additions & 0 deletions src/aleph/vm/hypervisors/qemu/qemuvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ def send_shutdown_message(self):
logger.warning("unexpected answer from VM", resp)
print("shutdown message sent")
client.close()

async def teardown(self):
"""Stop the VM."""
self.send_shutdown_message()

0 comments on commit a3c5a8c

Please sign in to comment.