You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use set_rt_frame_socket to send individual frames to my light strings. These are shown for 60 seconds before the string reverts to its last stored movie. Because the xled.control.ControlInterface does not set a short timeout when communicating with the lights, sometimes I see many-minute hangs during which communication is lost. These failed connections are intermittent, so in the absence of an xled timeout argument I’ve found that this wrapper class works well:
classTimeoutControlInterface:
interface=Nonedef__init__(self, *args, **kwargs):
"""Initialize xled.control.ControlInterface with same arguments"""self.interface=xled.control.ControlInterface(*args, **kwargs)
def__getattr__(self, name):
"""Retrieve versions of self.interface methods that use a threaded timeout"""original_method, responses=getattr(self.interface, name), []
defwrapped_method(*args, **kwargs):
"""Call the original method and stash its response"""responses.append(original_method(*args, **kwargs))
defthreaded_method(*args, **kwargs):
"""Call the wrapped method inside a thread and return its response"""thread=threading.Thread(target=wrapped_method, args=args, kwargs=kwargs)
thread.start()
thread.join(timeout=5.0)
ifthread.is_alive():
raiseException("Thread still alive")
returnresponses[0]
returnthreaded_method
It’s used just like xled.control.ControlInterface but raises an exception when a method call requires more than five seconds to complete. Hope it’s useful to someome!
The text was updated successfully, but these errors were encountered:
I use
set_rt_frame_socket
to send individual frames to my light strings. These are shown for 60 seconds before the string reverts to its last stored movie. Because thexled.control.ControlInterface
does not set a short timeout when communicating with the lights, sometimes I see many-minute hangs during which communication is lost. These failed connections are intermittent, so in the absence of anxled
timeout argument I’ve found that this wrapper class works well:It’s used just like
xled.control.ControlInterface
but raises an exception when a method call requires more than five seconds to complete. Hope it’s useful to someome!The text was updated successfully, but these errors were encountered: