Python Forum
calling a class multiple times - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: calling a class multiple times (/thread-7994.html)



calling a class multiple times - GOB - Feb-02-2018

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!


RE: calling a class multiple times - Gribouillis - Feb-02-2018

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


RE: calling a class multiple times - GOB - Feb-02-2018

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?