Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU 100% busy on Raspberry #24

Open
vagfed opened this issue Jul 14, 2020 · 11 comments
Open

CPU 100% busy on Raspberry #24

vagfed opened this issue Jul 14, 2020 · 11 comments

Comments

@vagfed
Copy link

vagfed commented Jul 14, 2020

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:

client = SinricPro(appKey, deviceIdArr, callbacks, event_callbacks=None, enable_log=False, restore_states=True, secretKey=secretKey)
udp_client = SinricProUdp(callbacks,deviceIdArr,enable_trace=False)
client.handle_all(udp_client)
@thegoliathgeek
Copy link
Contributor

It's happening because one thread is completely dedicated to udp actions (offline).

@kakopappa
Copy link
Contributor

may be commented it for now?

@vagfed
Copy link
Author

vagfed commented Jul 16, 2020

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)

@thegoliathgeek
Copy link
Contributor

I'll update this and make udp optional.

@thegoliathgeek
Copy link
Contributor

Hello @vagfed . I just updated python-sdk and made udp optional. You can try again with latest version.

@marcoaltomonte
Copy link

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)

@marcoaltomonte
Copy link

In _sinricprosocket.py in function async def handle the first while True is a busy loop.

@marcoaltomonte
Copy link

marcoaltomonte commented Dec 8, 2020

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

@thegoliathgeek
Copy link
Contributor

hi @marcoaltomonte.
Made the sleep customizable to avoid this issue.

client.handle_all(udp_client, sleep=1)

Please check out this in new update

@djschwab
Copy link

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

@djschwab
Copy link

djschwab commented Nov 19, 2021

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:
# Select as per your requirements
# 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants