'cant create guest session in virtualbox

I'm making automation to upload and execute files in virtual box with python. but sometimes guest session not being created.

 def turn_on(self):
        progress = self.machine.launch_vm_process(self.session, "gui", [])
        progress.wait_for_completion()
        start_time = time.time()
        
        while time.time() - start_time < 30:
            try:
                self.gs = self.session.console.guest.create_session(self.user_name, self.password)
                proc, stdout, stderr = self.gs.execute("C:\\Windows\\System32\\cmd.exe",
                                                ["/C","whoami"])
                return
            except:
                time.sleep(2)
                
        raise TimeoutError("Failed to connect to machine within 30 seconds")

when I checked the 'session information' in virtual box when GS wasn't created I saw it was terminated. img can anyone help me fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source