Python Forum

Full Version: calling a class multiple times
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I am trying to make a loop that calls a class multiple times. It is to write text on an LED screen, and the text changes after each loop.

The beginning of the class looks like this:

class RunText(SampleBase):
    def __init__(self, *args, **kwargs):
        super(RunText, self).__init__(*args, **kwargs)
        self.parser.add_argument("-t", "--text", help="The text to scroll on the RGB LED panel", default="ERROR")

    def run(self):
        offscreen_canvas = self.matrix.CreateFrameCanvas()
        offscreen_canvas.Clear()
        font = graphics.Font()
        font.LoadFont("../../../fonts/8x13B.bdf")
        Green = graphics.Color(0, 255, 0)
        Red = graphics.Color(255, 0, 0)
        Yellow = graphics.Color(255, 255, 0)
and the main function looks like this:

if __name__ == "__main__":

    lit_time = 55 #this controls how long the LED's stay lit; align this with cron scheduler
    
    try:
        trail_info = GetInfo()
        for x in range(0,3):
                run_text = RunText()
                if (not run_text.process()):
                    run_text.print_help()
                
        ##time.sleep(10)

        
    except:
        print "can't get data"
        run_text_error=RunTextError()
        if (not run_text_error.process()):
            run_text_error.print_help()
        time.sleep(lit_time)
        
When I try to run it though, the RunText class runs once well, but then after that I get the error

Quote:"Must run as root to be able to access /dev/mem
Prepend 'sudo' to the command.

(and I get a segmentation fault.

I think that the class is trying to get info from the command line again and can't, even though it was able to get that info for the fist go around in the loop (I am running the script as sudo from the shell).

Would really appreciate any help!

Thanks!
We don't see where the code tries to access /dev/mem in your program. Is it launching a subprocess without sudo?
Thanks for the reply.

Hmm, I'm looking for where that happens but haven't been able to find it in the code yet - but why would it work the first time through the loop but not subsequent ones?