AshleyC
Posts: 26
Joined: Sat Jun 16, 2012 1:34 pm
Location: Derby

Python Loop

Thu Jun 06, 2013 4:56 pm

I have a python script on a loop monitoring digital inputs (home alarm) I have noticed that the cpu indicator is quite high and as i don't have a pause/sleep line in my script i was wondering if placing a pause would help and if so by how much would you say?

Cheers

User avatar
bob_binz
Posts: 441
Joined: Thu Feb 02, 2012 7:58 pm
Location: Stockport, UK

Re: Python Loop

Thu Jun 06, 2013 7:17 pm

Depends how often you need to poll your inputs - are they momentary changes or will they be made for a good period? A delay of 1 second in your loop will have significant saving on processor utilisation

jrmedd
Posts: 20
Joined: Mon Oct 29, 2012 3:48 pm

Re: Python Loop

Fri Jun 07, 2013 7:29 am

When using a PIR sensor, I've found delays of 0.5 to 1 second are acceptable, given that the sensor stays in the 'triggered' state for a couple of seconds anyway.

timhoffman
Posts: 85
Joined: Sat Nov 05, 2011 11:31 pm

Re: Python Loop

Sun Jun 09, 2013 9:51 am

I would consider using interrupts rather than a busy wait loop.

Have a look at this article http://raspi.tv/2013/how-to-use-interru ... d-rpi-gpio

Return to “Python”