virtualbox-python icon indicating copy to clipboard operation
virtualbox-python copied to clipboard

Can't register for machine state change events

Open mcpeldot opened this issue 5 years ago • 1 comments

When I run the following snippet:

import virtualbox
from virtualbox.library import MachineState
def on_machine_state_changed(event):
    print(event)
vbox = virtualbox.VirtualBox()
vbox.register_on_machine_state_changed(on_machine_state_changed)

I get the following stack trace:

Unhanded exception in callback: Traceback (most recent call last): File "C:\Python38\lib\site-packages\virtualbox\events.py", line 56, in event_monitor callback(event_interface(event)) File "C:\Python38\lib\site-packages\virtualbox\library_base.py", line 130, in init self.i = manager.cast_object(interface, self.class).i File "C:\Python38\lib\site-packages\virtualbox_init.py", line 197, in cast_object i = self.manager.queryInterface(interface_object.i, name) File "C:\Python38\lib\site-packages\vboxapi_init.py", line 1082, in queryInterface return self.platform.queryInterface(oIUnknown, sClassName) File "C:\Python38\lib\site-packages\vboxapi_init.py", line 679, in queryInterface return CastTo(oIUnknown, sClassName) File "C:\Python38\lib\site-packages\win32com\client_init.py", line 141, in CastTo ob = gencache.EnsureDispatch(ob) File "C:\Python38\lib\site-packages\win32com\client\gencache.py", line 527, in EnsureDispatch disp = win32com.client.Dispatch(prog_id) File "C:\Python38\lib\site-packages\win32com\client_init_.py", line 96, in Dispatch return _WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx) File "C:\Python38\lib\site-packages\win32com\client_init.py", line 43, in __WrapDispatch return dynamic.Dispatch(dispatch, userName, WrapperClass, typeinfo, clsctx=clsctx) File "C:\Python38\lib\site-packages\win32com\client\dynamic.py", line 133, in Dispatch typeinfo = IDispatch.GetTypeInfo() AttributeError: 'NoneType' object has no attribute 'GetTypeInfo'

Exception in thread Thread-1: Traceback (most recent call last): File "C:\Python38\lib\site-packages\virtualbox\library_base.py", line 201, in _call_method ret = method(*in_params) File "C:\Users\me\AppData\Local\Temp\gen_py\3.8\D7569351-1750-46F0-936E-BD127D5BC264x0x1x3.py", line 3397, in EventProcessed return self.oleobj.InvokeTypes(1610743814, LCID, 1, (24, 0), ((9, 1), (9, 1)),aListener pywintypes.com_error: (-2147417851, 'The server threw an exception.', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner self.run() File "C:\Python38\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "C:\Python38\lib\site-packages\virtualbox\events.py", line 60, in _event_monitor event_source.event_processed(listener, event) File "C:\Python38\lib\site-packages\virtualbox\library.py", line 30696, in event_processed self._call("eventProcessed", File "C:\Python38\lib\site-packages\virtualbox\library_base.py", line 192, in _call return self._call_method(method, in_p=in_p) File "C:\Python38\lib\site-packages\virtualbox\library_base.py", line 214, in _call_method errobj.msg = exc.args[2][2] TypeError: 'NoneType' object is not subscriptable

And if busy wait or otherwise keep the script from exiting, the handler doesn't get called when I change the VM state (eg, shut it down or start it up).

Windows 10 Pro virtual box 6.1.8 Python 3.8.3

  • pywin32 227
  • vboxapi 1.0

mcpeldot avatar May 22 '20 21:05 mcpeldot

I don't have a lot of time to work on this library. If you figure out the issue and have a patch I'd happily review it.

sethmlarson avatar May 22 '20 22:05 sethmlarson