RevPiModIO 20ms Exceeded - Can not hold cycle time

Moderator: RevPiModIO

Post Reply
waischa
Posts: 8
Joined: 06 Jun 2023, 11:30
Answers: 0

RevPiModIO 20ms Exceeded - Can not hold cycle time

Post by waischa »

Hi all,

I have encountered this problem:

Code: Select all

/usr/lib/python3/dist-packages/revpimodio2/helper.py:617: RuntimeWarning: cycle time of 20 ms exceeded - can not hold cycle time!
  RuntimeWarning
Why is this happening? My code has been running for 3 days straight until this error began to pop up and then proceed to freeze my entire RevPi. I cannot click, keyboard doesn't work but I am able to ping RevPi.

Is this a RevPi memory problem, meaning i need to refresh it from time to time to prevent the freeze? Any guidance is appreciated.

Thank you! :)
User avatar
RevPiModIO
KUNBUS
Posts: 322
Joined: 20 Jan 2017, 08:44
Answers: 0
Contact:

Re: RevPiModIO 20ms Exceeded - Can not hold cycle time

Post by RevPiModIO »

Hi waisha.

It looks like a resource problem on the RevPi. Of course, when the CPU is busy and the system starts to be unoperable, revpimodio2 can of course no longer maintain the cycle time and these warnings are issued.

We now have to find out what is happening there.

- In the command line, for example, you could use `htop` to display CPU and RAM consumption. Then you can also find the responsible process.

If it is your Python program, I suspect that several times `revpimodio2. RevPiModIO(autorefresh=True)` is called. Only a single RevPiModIO instance may exist, old instances must be terminated cleanly by calling `.exit()`.

Bad example:

Code: Select all

import revpimodio2
from time import sleep

for i in range(5):
	rpi = revpimodio2.RevPiModIO(autorefresh=True)
	
	rpi.io.O_1.value = True
	sleep(10)
	rpi.io.O_1.value = False
	sleep(10)
	
	# Now the important part, which will free the resources
	rpi.exit()
The example is supposed to make the output O_1 flash, but if you did not call `rpi.exit()` at the end, more and more instances would be created that remain active in memory and the CPU through the `autorefresh`.

That's how it should be done

Code: Select all

import revpimodio2
from time import sleep

# Do this just once in your program and use this object
rpi = revpimodio2.RevPiModIO(autorefresh=True)

for i in range(5):
	rpi.io.O_1.value = True
	sleep(10)
	rpi.io.O_1.value = False
	sleep(10)
	
# At the end of the program call exit to make sure all data is written to process image
rpi.exit()
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
waischa
Posts: 8
Joined: 06 Jun 2023, 11:30
Answers: 0

Re: RevPiModIO 20ms Exceeded - Can not hold cycle time

Post by waischa »

Hi,
- In the command line, for example, you could use `htop` to display CPU and RAM consumption. Then you can also find the responsible process.
I have tried to type `htop` in the command prompt but nothing pop up, it just goes to the next line and nothing else.

Next, my autorefresh is indeed out of the loop, it was only called once in the beginning.

This is my code in short:

Code: Select all

rpi=revpimodio2.RevPiModIO(autorefresh=True)

rpi.handlesignalend()
rpi.core.green.value = 0
rpi.core.red.value = 1
rpi.core.green2.value = 0
rpi.core.red2.value = 1
rpi.exitsignal.wait(0.5)
rpi.core.a1green.value = 1
rpi.core.a1red.value = 0
rpi.core.a2green.value = 1
rpi.core.a2red.value = 0

while True:
	Server()
	Client()
	Read_SP()
	time.sleep(0.5)
I am unsure how autorefresh work completely, do I have to apply the autorefresh to all the IO I have in the program?
Post Reply