adrian5750
Posts: 27
Joined: Mon Mar 06, 2017 10:10 pm

RPi 3 / VNC / lockup after 30 hours running

Thu Aug 09, 2018 7:38 am

HI Folks

I'm trying to use an RPi for monitoring temperature in a glass-fusing kiln, using the MAX31855 and the Adafruit 'simpletest.py' code as a test rig.
I've previously had a setup with my own code, which worked well, displaying a graph of time vs temperature, which I could view remotely using VNC Server / VNC Viewer and a wi-fi connection to my Win10 pc. For debug purposes, the Pi also has its own screen.
Latest install of operating system, plus updates.

The only fly in the ointment was that the Pi would lock up, from time to time - with both red & green leds full on.

To try and debug this, I've put the Pi on my bench beside the computer, and am running a slightly modified version of the 'simpletest.py' code, that includes a counter - just to see if there's any pattern to the locking up.

The logic of the code is
- read temperature from the MAX31855
- print counter
- print temperature/60 (so it displays minutes run)
- sleep 1
- increment counter
loop

I've done four test runs so far - they all fail in the region of 1824 to 1860 minutes - or about 30 hours.

I tried the
sudo iwconfig wlan0 power off
but that didn't seem to make any difference

On the test that I'm running now, I've changed the VNC Server idle timeout from 3600 to 0 - but I'm not holding my breath...

Any ideas, please?
Running Stretch and uname -a returns 4.14.50-v7+ #1122 SMP Tues Jun 19 12:26:26 BST arm7l GNU/Linux

Many thanks
Adrian

klricks
Posts: 5838
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: RPi 3 / VNC / lockup after 30 hours running

Thu Aug 09, 2018 12:45 pm

adrian5750 wrote:
Thu Aug 09, 2018 7:38 am
..........
On the test that I'm running now, I've changed the VNC Server idle timeout from 3600 to 0 - but I'm not holding my breath...
....
That will keep VNC from disconnecting after 1 hour.

Try running top and monitor memory usage.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

adrian5750
Posts: 27
Joined: Mon Mar 06, 2017 10:10 pm

Re: RPi 3 / VNC / lockup after 30 hours running

Thu Aug 09, 2018 12:57 pm

klricks wrote:
adrian5750 wrote:
Thu Aug 09, 2018 7:38 am
..........
On the test that I'm running now, I've changed the VNC Server idle timeout from 3600 to 0 - but I'm not holding my breath...
....
That will keep VNC from disconnecting after 1 hour.

Try running top and monitor memory usage.
Thanks for the reply. Yes - I didn't think that the VNC timeout was the culprit - but worth a try.....
especially when you're getting desperate! <grin>

I'd not come a cross 'top' - in googling I found 'htop' which seems to be a similar thing, so I've installed it and am now running it.
Currently showing
1 6%
2 2%
3 0%
4 0%
Mem 238M/927M
Swp 0k/100M

I guess it's a matter of running my test program until it locks up, and seeing what 'htop' says?

For what it's worth - here's the actual python program..
don't know if there's anything obvious that I've done wrong here...

Thanks
Adrian

#!/usr/bin/python
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Can enable debug output by uncommenting:
#import logging
#logging.basicConfig(level=logging.DEBUG)

import time

import Adafruit_GPIO.SPI as SPI
import Adafruit_MAX31855.MAX31855 as MAX31855


# Define a function to convert celsius to fahrenheit.
def c_to_f(c):
return c * 9.0 / 5.0 + 32.0


# Uncomment one of the blocks of code below to configure your Pi or BBB to use
# software or hardware SPI.

# Raspberry Pi software SPI configuration.
CLK = 25
CS = 24
DO = 18
sensor = MAX31855.MAX31855(CLK, CS, DO)

# Raspberry Pi hardware SPI configuration.
#SPI_PORT = 0
#SPI_DEVICE = 0
#sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

# BeagleBone Black software SPI configuration.
#CLK = 'P9_12'
#CS = 'P9_15'
#DO = 'P9_23'
#sensor = MAX31855.MAX31855(CLK, CS, DO)

# BeagleBone Black hardware SPI configuration.
#SPI_PORT = 1
#SPI_DEVICE = 0
#sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

# Loop printing measurements every second.
print('Press Ctrl-C to quit.')
counter = 0
while True:
temp = sensor.readTempC()
internal = sensor.readInternalC()
print((counter / 60))
print(' Temperature: {0:0.1F}*C '.format(temp, c_to_f(temp)))

time.sleep(1.0)
counter = (counter + 1)

adrian5750
Posts: 27
Joined: Mon Mar 06, 2017 10:10 pm

Re: RPi 3 / VNC / lockup after 30 hours running

Thu Aug 09, 2018 4:16 pm

Interesting - looks as if running the script though Idle (which I was) causes a slow increase in memory usage

Mem used at the start of running the program was 238Meg
After 4 hours, was up to 368 Meg.
Could this behavour eventually cause the Pi to run out of memory and hang?
Say (368-238) / 4 = 32 meg 'leak' per hour
Run for 30 hours - gives 975 Mb
My max memory (htop) is showing as 927Mb - so it's in the right ballpark....

Stopping the program didn't release any memory.
Rebooting, running htop, and running the 'simpletest.py' script via 'sudo' results in Memory usage of 103Mb to start with - will now watch the program running for a while to see if memory usage creeps up

Interesting......
Adrian

adrian5750
Posts: 27
Joined: Mon Mar 06, 2017 10:10 pm

Re: RPi 3 / VNC / lockup after 30 hours running

Sat Aug 11, 2018 6:33 am

Hi Folks

Update - 38 hours later.... test program still running fine. Memory showing 114Mb out of 927.

It's perhaps unfair to accuse Idle of having a 'Memory leak' - I guess if it's creating a logfile of activity to allow the user to trawl back and investigate a problem then that logfile has got to go somewhere, and it's got to have a size... but it's a bit unfortunate that Idle seems to allow the logfiles to grow and grow until they kill the RPi...

Anyway - something learned, I think.
Use Idle for tweaking / editing / debugging - but switch to running the python script via 'sudo python3 <script>' in order to do tests of long-term operation.

Will deploy the RPi back into the 'real world' later today, running the proper program, and expect it to run 'forever'..... <grin>

Thanks for the suggestion about top / htop
Adrian

DirkS
Posts: 9065
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: RPi 3 / VNC / lockup after 30 hours running

Sat Aug 11, 2018 7:09 am

Anyway - something learned, I think.
Use Idle for tweaking / editing / debugging - but switch to running the python script via 'sudo python3 <script>' in order to do tests of long-term operation.
Actually, I would cut out Idle completely.
Try Thonny or Mu

adrian5750
Posts: 27
Joined: Mon Mar 06, 2017 10:10 pm

Re: RPi 3 / VNC / lockup after 30 hours running

Sat Aug 11, 2018 7:13 am

Thanks - I'll give them a try.....
Adrian

Return to “Troubleshooting”

Who is online

Users browsing this forum: No registered users and 40 guests