Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithm effect on the CPU
#3
Hello, some thought
I believe too things are imbricated in your program.
1 - It does loop and then after(5,loop), which stack again your loop into the system, probably increasing the stack, which is wrong.
2 - In "loop()", an "except: prgloop()" which does the same "after(5,loop)". If an exception occurs, it will stacked, and if a new one occurs, you will reach eventually the python exception stack limit. Not very important because you will be notified.
3 - If I'm good, "after(5,loop)" means you start the loop again after 5ms. It's very few, and it could be the reason of your cpu time waste. I don't know Tk, but in the GUI I know, I never do that because... it does use a lot of CPU for nothing. The purpose of a GUI system is to react after a GUI event, not to process some other system, like for instance a serial device. Anyway, you stack a new loop every 5ms, and this is wrong. You can get a proof of that if the free memory of your system decreases regularly (try htop utility on your RPI, in the standard repository). If it does not, I'm wrong, but I'm sure it cannot be a good practice.
What you can do is :
- change your code to make the GUI starting events as it wants and terminate the event processing as quickly as possible, and don't start something long at the end of this event process.
- process the serial line in another thread, which will live alone and won't use too much the CPU. There are excellent threading modules coming with python ; choose one compatible with Tk. Does somebody has any hint about that ?. You can look and post in the GUI forum.
- If you don't have any other solution, increase the 5ms (try for instance 20ms). You can also try the time module (ex: time.sleep(0.2)) which is good to give your system some breath.
Reply


Messages In This Thread
Algorithm effect on the CPU - by Faruk - Dec-19-2018, 06:26 AM
RE: Algorithm effect on the CPU - by Larz60+ - Dec-19-2018, 08:14 AM
RE: Algorithm effect on the CPU - by jeanMichelBain - Dec-19-2018, 08:32 AM
RE: Algorithm effect on the CPU - by Faruk - Dec-19-2018, 08:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing effect sizes for variables in an anova eyavuz21 2 1,023 Feb-01-2023, 02:12 PM
Last Post: eyavuz21
  Help with TypeWriter Effect in Python Rich Extra 0 1,209 May-23-2022, 09:44 PM
Last Post: Extra
  Rotation Effect on live Webcam Feed Leziiy 0 1,634 Sep-12-2020, 04:25 PM
Last Post: Leziiy
  How to fix statement seems to have no effect hernancrespo89 0 6,894 Jan-23-2020, 09:23 PM
Last Post: hernancrespo89
  strange effect from duplicating a file descriptor Skaperen 1 2,091 Feb-18-2019, 08:20 PM
Last Post: Skaperen
  "Statement has no effect" birdieman 21 17,357 Jan-27-2017, 02:59 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020