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

#124 fix register listener #152

Closed KarloDipetrio closed 1 year ago

KarloDipetrio commented 4 years ago

Closes #124

sethmlarson commented 4 years ago

The problem is is virtualbox/library.py is automatically generated so this likely means we need to update build.py. Maybe we can update the interface return value script to check for None values and if None to return None? What do you think of this?

KarloDipetrio commented 4 years ago

The problem is is virtualbox/library.py is automatically generated so this likely means we need to update build.py. Maybe we can update the interface return value script to check for None values and if None to return None? What do you think of this?

Hm... What about events.py?

def _event_monitor(callback, event_source, listener, event_interface, quit):
    global _callbacks
    try:
        while not quit.is_set():
            try:
                event = event_source.get_event(listener, 1000)
            except library.VBoxError:
                print("Unregistering %s due to VBoxError on get_event" %
                      listener, file=sys.stderr)
                break
            if event:
                try:
                    callback(event_interface(event))
                except Exception:
                    print("Unhanded exception in callback: \n%s" %
                          traceback.format_exc(), file=sys.stderr)
                event_source.event_processed(listener, event)
    finally:
        _callbacks.pop(threading.current_thread().ident, None)
        try:
            event_source.unregister_listener(listener)
        except Exception:
            print("Failed to unregister listener %s" % listener,
                  file=sys.stderr)

maybe we could do something like this?

def _event_monitor(callback, event_source, listener, event_interface, quit):
    global _callbacks
    try:
        while not quit.is_set():
            try:
                event = event_source.get_event(listener, 1000)
            except library.VBoxError:
                print("Unregistering %s due to VBoxError on get_event" %
                      listener, file=sys.stderr)
                break
            event_type = getattr(event, 'type_p', None)
            if event_type :
                try:
                    callback(event_interface(event))
                except Exception:
                    print("Unhanded exception in callback: \n%s" %

event_type = getattr(event, 'type_p', None) if not event_type means its None event

sethmlarson commented 1 year ago

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