I am using pymodbus to collect some data from sensors 4 reading every sec. The program is in continuous loop but the problem is raspberry pi freezing every few hours (60 hr).

The code stops automatically. cannot ping device but cronjobs running fine.

Using ethernet for some other activity tends to deepen the problem as now its freezing more quickly (8 hrs).

I have checked that memory usage and system usage, both are fine.

The code is at Github.

2 Answers 2


The Raspberry Pi has a built in hardware watchdog timer.

For Raspbian

To load the watchdog kernel module right now, issue the following command:

$ sudo modprobe bcm2708_wdog

Load the module the next time the system boots, add a line to your /etc/modules file with "bcm2708_wdog". The -a option makes sure tee appends instead.

$ echo "bcm2708_wdog" | sudo tee -a /etc/modules

Open /etc/watchdog.conf with your favorite editor

$ sudo nano /etc/watchdog.conf

Uncomment the line that starts with #watchdog-device by removing the hash (#) to enable the watchdog daemon to use the watchdog device.

Uncomment the line that says #max-load-1 = 24 by removing the hash symbol to reboot the device if the load goes over 24 over 1 minute. A load of 25 of one minute means that you would have needed 25 Raspberry Pis to complete that task in 1 minute. You may tweak this value to your liking.

Install chkconfig if you don't already have it

$ sudo apt-get install chkconfig
$ sudo chkconfig watchdog on

You can test it by doing a fork bomb in the console.

:(){ :|:& };:

This is the professional way of restarting any kind of hardware or listening for certain events. You can even use the watchdog to start certain scripts based on the data you are gettings. Like high wind speeds can send you warning email or something ...



if you have cron jobs running, just set up daily automatic reboot -- this should restart your software every 24hours, that's within your 60hr running limit. you might lose about 5-10seconds worth of data, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.