Open vagfed opened 4 years ago
It's happening because one thread is completely dedicated to udp actions (offline).
may be commented it for now?
If I comment the udp_client = SinricProUdp(callbacks,deviceIdArr,enable_trace=False)
line I can no longer call client.handle_all(udp_client)
. How should I use the SinricPro object to make it handle Alexa data?
The handle_all
function uses udp_client in both threads and I think the t1 is the one that handled Alexa data,
def handle_all(self, udp_client):
try:
t1 = Thread(target=self.handle_clients, args=(self.socket.handle, udp_client))
t2 = Thread(target=udp_client.listen)
I'll update this and make udp optional.
Hello @vagfed . I just updated python-sdk and made udp optional. You can try again with latest version.
I have the same problem. My main function is now: client = SinricPro(appKey, deviceIdArr, callbacks, enable_log=False,restore_states=True,secretKey=secretKey) client.handle_all(None)
In _sinricprosocket.py in function async def handle the first while True is a busy loop.
Fixed by adding: 1) from time import sleep 2) sleep(1) between "while True" and "while queue.qsize() > 0:" in handle function in _sinricprosocket.py
hi @marcoaltomonte. Made the sleep customizable to avoid this issue.
client.handle_all(udp_client, sleep=1)
Please check out this in new update
Are these changes part of version 2.4.2 or 2.4.1? I still have 100% cpu usage with this code: client = SinricPro(appKey, deviceIdArr, callbacks, event_callbacks=event_callback, enable_log=False,restore_states=True,secretKey=secretKey) udp_client = SinricProUdp(callbacks,deviceIdArr,enable_trace=False) client.handle_all(udp_client,sleep=1)
I am using version 2.4.1 that was installed with: pip3 install sinricpro
I found that for me the only way to reduce cpu usage was to add a delay in the Events() procedure. I also found that on my Linux machine my program would become unresponsive after 15 minutes or so if I didn't also include the call to client.event_handler.raiseEvent in the procedure.
def Events(): while True:
# REMOVE THE COMMENTS TO USE
time.sleep(300) # needed to keep cpu time < 100%
# if this call is not included, device code becomes non-responsive after 15 minutes
client.event_handler.raiseEvent(device1, 'setPowerState',data={'state': 'On'})
pass
I have just started to use sinricpro python library on a Raspberry pizero and CPU is constantly at 100% with processor quite hot. Probably there is an event loop very tight. Is there a way to reduce CPU load? I basically use three lines of code: