MarkDH102
Posts: 329
Joined: Fri Feb 13, 2015 3:18 pm

Very odd error on program termination

Fri Apr 27, 2018 8:02 am

My code had been running for a few weeks 24/7 then today it did something very odd, so I clicked the EXIT button (on my tkinter window) to be met by the following screen. The program cleaned up its files and terminated normally (or so it seemed).
I am suspecting some sort of memory corruption in the Python interpreter (possibly down to my program?)
The first 3 lines are output from my program and can be ignored.
The program is run from the terminal, not from within Idle. Nothing else of mine is running on the Pi.
Does anyone have any ideas?
WeirdError.png
WeirdError.png (143.24 KiB) Viewed 973 times

User avatar
thagrol
Posts: 1722
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Very odd error on program termination

Fri Apr 27, 2018 11:29 am

It's hard to say without seeing your code (and I don't know Tkinter) but the error suggests that you've not initialised the GPIO library correctly )or at all). Either that or said configuration has been lost.

I'd suggest you check your code and see where, if at all, the call to GPIO.setmode takes place. It should probably be early in the program, before any callbacks from tkinter can occur. My guess is that you're calling it in the wrong place such that it is possible for your "exit" button code to call an uninitialised GPIO library.

Of course, without your code this is all just guess work.
This space unintentionally left blank.

MarkDH102
Posts: 329
Joined: Fri Feb 13, 2015 3:18 pm

Re: Very odd error on program termination

Fri Apr 27, 2018 11:36 am

I do call the GPIO setmode() function once at startup and then in the exitbutton() function, I call the GPIO cleanup(). The code has been running fine calling gpio functions for the last few weeks without a restart.
I've never seen a python trace like that and that's why I wondered if the interpreter had gone awol.

User avatar
thagrol
Posts: 1722
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Very odd error on program termination

Fri Apr 27, 2018 12:22 pm

MarkDH102 wrote:
Fri Apr 27, 2018 11:36 am
I do call the GPIO setmode() function once at startup and then in the exitbutton() function, I call the GPIO cleanup(). The code has been running fine calling gpio functions for the last few weeks without a restart.
I've never seen a python trace like that and that's why I wondered if the interpreter had gone awol.
Can't comment on what the interpreter is doing but a further though occurs: is it possible that the call to GPIO.outpuit (line 653) is occurriong after the call to GPIO.cleanup?
This space unintentionally left blank.

hippy
Posts: 5623
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Very odd error on program termination

Fri Apr 27, 2018 12:59 pm

thagrol wrote:
Fri Apr 27, 2018 12:22 pm
is it possible that the call to GPIO.outpuit (line 653) is occurriong after the call to GPIO.cleanup?
My money would be on that or similar. I have created similar problems for myself when I have 'pulled the rug from under the feet of my code' during exit or closing down, trying to use things which have been 'closed down'.

It's far more likely to be some sort of programming or design error rather than interpreter failure. A few print statements, relying on a conditional 'closing' flag perhaps, may reveal what's happening, what program flow is leading to the error.

User avatar
PeterO
Posts: 4882
Joined: Sun Jul 22, 2012 4:14 pm

Re: Very odd error on program termination

Fri Apr 27, 2018 1:03 pm

It looks more like some code is trying to interact with a widget after the widget has been removed as Tk closes down.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

MarkDH102
Posts: 329
Joined: Fri Feb 13, 2015 3:18 pm

Re: Very odd error on program termination

Fri Apr 27, 2018 1:26 pm

I guess it is possible some code has carried on running prior to full exit of the code causing the actual GPIO error, but what I don't understand is the "invalid command name" messages. Is it possible that it is something the tkinter engine is putting out?

Like I say, the program behaved quite oddly before I shut it down. And it has run for a few weeks now without issue.
I've put some debugging statements in just in case it happens again and I've shut down the tkinter root.after() function I was using prior to cleanup of the GPIO.

Anyway, thanks everyone for your responses.

hippy
Posts: 5623
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Very odd error on program termination

Fri Apr 27, 2018 2:30 pm

MarkDH102 wrote:
Fri Apr 27, 2018 1:26 pm
what I don't understand is the "invalid command name" messages. Is it possible that it is something the tkinter engine is putting out?
Possibly. It looks like what should probably have been some meaningfulish names are actually text representation of numbers, maybe decimal representation of addresses. It's likely an "x=str(y)" somewhere where 'y' is a number rather than text. Could be a coding error or some default somewhere.

There is obviously some cause and we can see the result of that but not its source. Unless one can replicate the problem, track it down, one can only guess what might have gone wrong, where and why.

User avatar
RogerW
Posts: 284
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Very odd error on program termination

Sun Apr 29, 2018 5:18 pm

How are you trapping the exit button? Do you have something like

Code: Select all

        bind('<Destroy>',on_destroy)
I have found that on_destroy gets called multiple times. I had to use a once only flag to stop cleanup code being executed more than once.

MarkDH102
Posts: 329
Joined: Fri Feb 13, 2015 3:18 pm

Re: Very odd error on program termination

Mon Apr 30, 2018 6:16 am

This is the code that executes when the button is pressed:

Code: Select all

def stopProg(e):
    print ("DEBUG: Exit prog")
    display.clear()
    display.write_display()
    GPIO.cleanup()
    root.destroy()
And this is the code that defines the button:

Code: Select all

btnExit=Button(root, text="Exit", width=30)
btnExit.bind('<Button-1>', stopProg)
btnExit.grid(row=3, column=0, columnspan=1, pady=1)
I am only seeing the print statement once. I use this technique in multiple applications...

User avatar
RogerW
Posts: 284
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Very odd error on program termination

Mon Apr 30, 2018 9:09 am

Probably not that then.

Return to “Python”