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

Can't register for machine state change events #141

Closed mcpeldot closed 1 year ago

mcpeldot commented 4 years ago

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

sethmlarson commented 4 years ago

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 commented 1 year ago

I no longer have time to maintain this library, so am closing this issue.