sethmlarson / virtualbox-python

Complete implementation of VirtualBox's COM API with a Pythonic interface.
https://pypi.org/project/virtualbox
Apache License 2.0
354 stars 75 forks source link

VM does not start: The session is not locked (state: Spawning) #39

Closed amazpyel closed 7 years ago

amazpyel commented 9 years ago

Environment: -Python 2.7.3 -Ubuntu 12.04.5 -pyvbox-0.2.2 -Virtual Box 4.3.30

I'm trying to launch virtual machine by means virtualbox python api but VM does not launch. Here is the log:

In [1]: import virtualbox

In [2]: vbox = virtualbox.VirtualBox()

In [3]: print("VM(s):\n + %s" % "\n + ".join([vm.name for vm in vbox.machines]))
VM(s):
 + win_7
 + eclipse_video

In [4]: session = virtualbox.Session()

In [5]: vm = vbox.find_machine('win_7')

In [6]: progress = vm.launch_vm_process(session, 'gui', '')

In [7]: h, w, _, _, _ = session.console.display.get_screen_resolution(0)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-7-22abc05fadf4> in <module>()
----> 1 h, w, _, _, _ = session.console.display.get_screen_resolution(0)

/usr/local/lib/python2.7/dist-packages/pyvbox-0.2.2-py2.7.egg/virtualbox/library.pyc in console(self)
  24089         Console object associated with this session.
  24090         """
> 24091         ret = self._get_attr("console")
  24092         return IConsole(ret)
  24093 

/usr/local/lib/python2.7/dist-packages/pyvbox-0.2.2-py2.7.egg/virtualbox/library_base.pyc in _get_attr(self, name)
    153 
    154     def _get_attr(self, name):
--> 155         attr = self._search_attr(name, prefix='get')
    156         if inspect.isfunction(attr) or inspect.ismethod(attr):
    157             return self._call_method(attr)

/usr/local/lib/python2.7/dist-packages/pyvbox-0.2.2-py2.7.egg/virtualbox/library_base.pyc in _search_attr(self, name, prefix)
    140         for i in range(3):
    141             for attr_name in attr_names:
--> 142                 attr = getattr(self._i, attr_name, self)
    143                 if attr is not self:
    144                     break

/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/client/__init__.py in __getattr__(self, attr)
    372                 self.QueryInterface(iid)
    373                 interface = self.__dict__['_interfaces_'][iid]
--> 374             return getattr(interface, attr)
    375         # Some interfaces may provide this name via "native" support.
    376         # Loop over all interfaces, and if found, cache it for next time.

/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/client/__init__.py in __getattr__(self, attr)
    458                 raise RuntimeError, "Can't get properties with this many args!"
    459             args = ( param_infos, () )
--> 460             return XPTC_InvokeByIndex(self._comobj_, method_index, args)
    461 
    462         # See if we have a method info waiting to be turned into a method.

Exception: 0x8000ffff (The session is not locked (session state: Spawning))

Thank you, Alex

mjdorma commented 9 years ago

Hi Alex,

I just tested this out against a 5.0.0 VirtualBox stable with the 1.0.0 branch (which is not stable or complete) and the following sequence worked:

import virtualbox
vbox = virtualbox.VirtualBox()
vm = vbox.find_machine('win7')
vm.launch_vm_process()
session = vm.create_session()
h, w, _, _, _, _ = session.console.display.get_screen_resolution(0)
png = session.console.display.take_screen_shot_to_array(0, h, w, virtualbox.library.BitmapFormat.png)
open('test.png', 'wb').write(png)
!open test.png

Note: VirtualBox API 5x get_screen_resolution now returns an extra parameter.

What if you tried to get a session after you've launched the vm process?

Regards, Mick

amazpyel commented 9 years ago

Hi Mick,

What if you tried to get a session after you've launched the vm process?

Session state is locked in this case and I can work with it (get screenshot in this case). So, do I need to run VM manually because launch_vm_process does not work with Virtual Box 4.3.30?

Thank you.

sethmlarson commented 7 years ago

Closing this issue as stale. If you are having this issue with the latest version of pyvbox w/ VirtualBox 5.1.x @amazpyel ping this issue and I'll re-open.