Python Forum
calling a class multiple times
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling a class multiple times
#1
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!
Reply
#2
We don't see where the code tries to access /dev/mem in your program. Is it launching a subprocess without sudo?
Reply
#3
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can I use logging in a class (without multiple messages) mevan 2 535 Oct-16-2023, 11:08 PM
Last Post: mevan
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 989 Sep-19-2022, 02:32 AM
Last Post: Xeno
Sad Iterate randint() multiple times when calling a function Jake123 2 1,979 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Calling a base class variable from an inherited class CompleteNewb 3 1,592 Jan-20-2022, 04:50 AM
Last Post: CompleteNewb
  Calling a class from a function jc4d 5 1,755 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  Calling functions from within a class: PYQT6 Anon_Brown 4 3,643 Dec-09-2021, 12:40 PM
Last Post: deanhystad
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 2,274 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  How to print string multiple times on new line ace19887 7 5,573 Sep-30-2020, 02:53 PM
Last Post: buran
  NameError when calling a class method mfreudenberg 2 2,254 Sep-25-2020, 07:40 AM
Last Post: mfreudenberg
  Copy mp3 file multiple times and rename Mar10 4 3,676 Sep-23-2020, 01:09 AM
Last Post: Mar10

Forum Jump:

User Panel Messages

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