jath03 / openrgb-python

A python client for the OpenRGB SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError when SDK server is not fully initialized

kickerofbottoms opened this issue · comments

I'm starting the server from the python process then repeatedly attempting a connection until it's ready, but it seems there's some short period where the server will respond to a connection but it's not actually ready, or openrgb-python has not yet received some initial state (just guessing here). It seems to work fine after a couple more attempts if I also handle the AttributeError in addition to the ConnectionRefusedError.

Traceback (most recent call last):
  File "C:/Users/user/Scripts/python/rgb/rgb_effects.py", line 30, in open_connection
    client = OpenRGBClient()
  File "C:\Users\user\Scripts\python\rgb\venv\lib\site-packages\openrgb\orgb.py", line 234, in __init__
    self.comms.requestDeviceNum()
  File "C:\Users\user\Scripts\python\rgb\venv\lib\site-packages\openrgb\network.py", line 123, in requestDeviceNum
    self.read()
  File "C:\Users\user\Scripts\python\rgb\venv\lib\site-packages\openrgb\network.py", line 94, in read
    self.callback(device_id, packet_type, buff[0])
  File "C:\Users\user\Scripts\python\rgb\venv\lib\site-packages\openrgb\orgb.py", line 243, in _callback
    if data != self.device_num or data != len(self.devices):
AttributeError: 'OpenRGBClient' object has no attribute 'devices'

Not a critical issue by any means, but repeatedly retrying a connection isn't an uncommon thing in general so it'd be nice it it were cleaner

commented

Should be fixed on the on the latest git version

That was a quick fix, no more AttributeError.

Unfortunately there still seems to be some sensitivity in the timing of various method calls.
client.get_devices_by_type(DeviceType.MOTHERBOARD) now returns an empty list when called too quickly after connecting. When adding ~10 seconds of sleep before calling it returns a single item as expected.

And calling zone.show() too quickly after calling device.set_mode('direct') leads to an OpenRGBDisconnected, but in this case it looks like OpenRGB itself is crashing (exit 3221225477), so I should probably open an issue over there.

Thanks for the work on the nice library. Let me know if you need any further details on anything

commented

Yeah, the problem is that OpenRGB starts the server before device detection is completed, so if you connect to the server in the small window before it's finished, not all of your devices will show up.

About the other problem, performing operations on the same device too quickly can cause some weird behavior. Iirc someone is working on improving the SDK server, but for now, try to put some kind of delay between operations on a single device.