Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trace invalid pointer
#1
Hello

I am using a python program i have writtent to collect machine data and send it via a socket to a server, the program does what it is supposed to do for 99% of the time but occasionally i am getting an error "*** Error in '/user/bin/python3': free(): invalid pointer: 0x00405340 ***"

After reserching this i am getting some quite complex information that is above my experience and have no way of tracing the root cause as when it happens it just crashes out to terminal window with the error message.

My skills are limited with Python but what i am looking for is an ability to trace the source/cause of the crash, this way i can resolve the issue, i am not looking for a solution to the cause just the route to find the problem if that makes sense?

What is the best way to find the line of code that has caused this error?

I have not posted any code as there are multiple modules, some compiled that i have imported from 3rd parties etc and to be honest i have no idea what code to post without an indication of the root cause?

Any pointers (that are not invalid Big Grin ) greatly appreciated

Thanks
Simon
Reply
#2
Post code of module causing error
Reply
#3
(Apr-15-2019, 08:56 AM)Larz60+ Wrote: Post code of module causing error

Hi
The problem i have is i dont know what module it is because when is crashes out i have no way to trace the line or module that i am aware of?
Reply
#4
At least show full error traceback.
Reply
#5
(Apr-15-2019, 11:24 AM)Larz60+ Wrote: At least show full error
I cannot see any traceback, just 1 line "*** Error in '/user/bin/python3': free(): invalid pointer: 0x00405340 ***"
Is this a problem happening outside of my programs but caused by the program, therefore no traceback?
As this is happening about 2 or 3 times a week across about 10 units i have to reset them as soon as it occures to keep the data flowing, i cannot recreate the problem as i do not know the root cause?

I can see that this looks like i am asking people to help me solve a problem with no information, the problem is i am unclear as to where to get the information from?
After a crash if there is no informationcaught by the program and nothing except the one line below showing in the terminal is it possible to get any trace information from elsewhere?

Simon
ps i have a .png of the terminal window on crash but no ability to post it.
Reply
#6
What packages are you importing into your code? I'm wondering if there is a non-standard package you are using that is causing the problem. Otherwise it would be something wrong with Python itself. It does sound like it is outside of your program, which would mean filing a bug report with the appropriate developers.

One way you could narrow down the source of the problem is with print lining. Just print every few lines what is being done at that point. Then the last print you see will give you a basic idea of where the problem is. Of course, if the volume of data you are process is large, this might not be viable.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#7
I am using FRAM memory to store values in and i have just noticed that i have not got any error trapping in that module, i am also using a 3rd party module, not sure if this could be a problem but it looks straight forward enough, below that i have also included my code for reading and writing to the FRAM, just started to add error trapping, not completed write section yet(apologies for any poor programming but i am learning Python)

#!/usr/bin/env python

# SDL_Pi_FRAM.py Python Driver Code
# SwitchDoc Labs 02/16/2014
# V 1.2


from datetime import datetime

import time
import smbus



class SDL_Pi_FRAM():
    

###########################
# SDL_Pi_FRAM Code
###########################
    def __init__(self, twi=1, addr=0x50):
        self._bus = smbus.SMBus(twi)
        self._addr = addr



    def write8(self, address, data):
        #print "addr =0x%x address = 0x%x data = 0x%x  " % (self._addr, address, data)
        self._bus.write_i2c_block_data(self._addr,address>>8, [address%256, data])



    def read8(self, address):

        self._bus.write_i2c_block_data(self._addr,address>>8, [address%256])
        returndata = self._bus.read_byte(self._addr) # this will read at the current address pointer, which we on the previous line
        #print "addr = 0x%x address = 0x%x %i returndata = 0x%x " % (self._addr, address, address, returndata)
        return returndata
import sys
import SDL_Pi_FRAM
import glob as gn
import time
import datetime
import logging
 
logging.basicConfig(level=logging.ERROR,
                    format='%(asctime)s %(levelname)s %(message)s',
                    filename='/home/pi/share/Data_Collection/errlog.log',
                    filemode='a')

def W():
    def MEMWrite (x,y,z):

        for q in range (y,z): #clear slot first
            fram.write8(q, 0)

            
        for letter in str(x):
            fram.write8(y, ord(letter))
            y+=1


    #print(time.time())

    fram = SDL_Pi_FRAM.SDL_Pi_FRAM(addr = 0x50)

    try:
        MEMWrite(gn.batchA,0,9)
    except BaseException as e:
        logging.error("FRAM Memory write error for batchA " + str(e))
    
        
        
    MEMWrite(gn.batchB,10,19)
    MEMWrite(gn.totalA,20,29)
    MEMWrite(gn.totalB,30,39)
    MEMWrite(gn.Job,40,49)
    MEMWrite(gn.TargetCycle,50,59)
    MEMWrite(gn.MachineName,60,69)
    MEMWrite(gn.ShiftCyclesInAuto,70,79)
    MEMWrite(gn.Shift,80,89)
    MEMWrite(gn.QtyShiftMade,90,99)
    MEMWrite(gn.ShiftDateTime,100,119)
    MEMWrite(gn.PartCode,120,169)
    MEMWrite(gn.myStatus,170,179)

    #print(time.time())
def R():
    def MEMRead (y,z): #value, start memory, end memory
        myStr=""
        for a in range(y,z):
            v=chr(fram.read8(a))
            if ord(v)!=0:  #if char is not "_" as this is used to clear locations
                myStr+=v
        return myStr

    fram = SDL_Pi_FRAM.SDL_Pi_FRAM(addr = 0x50)
    try:
        gn.batchA=int(MEMRead(0,9))
    except ValueError:
        gn.batchA=0
        logging.error("FRAM Memory read error for BatchA " + str(ValueError))
    try:
        gn.batchB=int(MEMRead(10,19))
    except ValueError:
        gn.batchB=0
        logging.error("FRAM Memory read error for BatchB " + str(ValueError))
    try:
        gn.totalA=int(MEMRead(20,29))
    except ValueError:
        gn.totalA=0
        logging.error("FRAM Memory read error for totalA " + str(ValueError))
    try:
        gn.totalB=int(MEMRead(30,39))
    except ValueError:
        gn.totalB=0
        logging.error("FRAM Memory read error for totalB " + str(ValueError))
    try:
        gn.Job=MEMRead(40,49)
    except ValueError:
        gn.Job='000000'
        logging.error("FRAM Memory read error for Job " + str(ValueError))
    try:
        gn.TargetCycle=MEMRead(50,59)
    except ValueError:
        gn.TargetCycle=0.0
        logging.error("FRAM Memory read error for TargetCycle " + str(ValueError))
    try:
        gn.MachineName=MEMRead(60,69)
    except ValueError:
        gn.MachineName='Not Set'
        logging.error("FRAM Memory read error for MachineName " + str(ValueError))
    try:
        gn.ShiftCyclesInAuto=MEMRead(70,79)
    except ValueError:
        gn.ShiftCyclesInAuto=0
        logging.error("FRAM Memory read error for ShiftCyclesInAuto " + str(ValueError))
    try:
        gn.Shift=MEMRead(80,89)
    except ValueError:
        gn.Shift='?'
        logging.error("FRAM Memory read error for Shift " + str(ValueError))
    try:
        gn.QtyShiftMade=MEMRead(90,99)
    except ValueError:
        gn.QtyShiftMade=0
        logging.error("FRAM Memory read error for QtyShiftMade " + str(ValueError))
    try:
        gn.ShiftDateTime=MEMRead(100,119)
    except ValueError:
        gn.ShiftDateTime=str(datetime.date.today())
        logging.error("FRAM Memory read error for ShiftDateTime " + str(ValueError))
    try:
        gn.PartCode=MEMRead(120,169)
        if gn.PartCode=='':
            gn.PartCode='No Part Code Set'
    except ValueError:
        gn.PartCode='No PartCode Set'
        logging.error("FRAM Memory read error for PartCode " + str(ValueError))
    try:
        gn.myStatus=MEMRead(170,179)
        if gn.myStatus=='':
            gn.myStatus='7' 
    except ValueError:
        gn.myStatus='7'
        logging.error("FRAM Memory read error for Status " + str(ValueError))
    
Reply
#8
(Apr-15-2019, 02:49 PM)simon149 Wrote: chabod801 wrote Yesterday, 06:09 PM:
Use Python tags (the python logo button) for blocks of code. The icode tags ([] button) is for inline code

Got it, thanks
Simon
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb trace library xxxlabradorxxx 1 1,119 Oct-01-2021, 11:30 PM
Last Post: Larz60+
  General pointer to start data4speed 3 1,911 Jul-01-2020, 06:18 AM
Last Post: DPaul
  Pointer in the right direction? Viking 5 2,677 Apr-22-2020, 06:14 PM
Last Post: Viking
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,742 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity
  Tracing a multiplication table w/ Python trace() NationalRex22 0 1,728 Jun-11-2019, 03:31 AM
Last Post: NationalRex22
  VM address (C pointer) of Python object Skaperen 1 2,013 Apr-21-2019, 10:57 PM
Last Post: hshivaraj
  Stack trace shows different exception type than print micseydel 5 4,362 Apr-01-2019, 10:24 PM
Last Post: micseydel
  How to create shadow between two colours and control a line after we trace it? CrazyPythonNerd 0 2,077 Mar-06-2019, 01:31 PM
Last Post: CrazyPythonNerd
  How to use python to receive Gobject.pointer stephenwei 0 2,533 Oct-30-2017, 04:56 PM
Last Post: stephenwei
  Debug and trace in python quocchi22101262 0 3,463 Jun-20-2017, 09:35 AM
Last Post: quocchi22101262

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020