Why does this class-scope variable not get updated in recursive function?
Question: I'm writing a small class for an LED controller, that runs as a process. The
idea is that some code runs constantly to blink LEDs over an i2c bus.

I'm new to OOP with Python, and I'm also new to Processes in python. I'm using
Multiprocessing with Python 3.4, but with the new print function should also
run in 2.7x.

If you run the code, I add three things to the blinkgroup list, which is shown
locally to have had an effect, however this never gets detected in the
ledblinkloop function, which calls itself so that it keeps running.

I suspect I've fundamentally mis-understood something in Python here.

    
    
    from multiprocessing import Process, Queue
    import time
    
    class LedController(Process):
        def __init__(self):     
            super(LedController, self).__init__()
            print("ledcontroller started: ",self.name)
            self.blinkgroup = [0x04,0x05]
    
        def run(self):
            self.ledblinkloop()
    
        def led_blink_on(self,led):
            if(led not in self.blinkgroup):
                print("LED not in blink group, adding. New blinkgroup length:",len(self.blinkgroup))
                self.blinkgroup.append(led)
    
        def ledblinkloop(self):
            print("Length of blinkgroup:",len(self.blinkgroup))
            time.sleep(1)
            self.ledblinkloop()
    
    class myclass:
        def __init__(self):
            ledcontroller = LedController()
            ledcontroller.start()
    
            while(1):
                time.sleep(5)
                ledcontroller.led_blink_on(0x08)
                ledcontroller.led_blink_on(0x09)
                ledcontroller.led_blink_on(0x10)
                time.sleep(5)
    
    if __name__ == "__main__":
    

Code should run as is with Python 3.


Answer: The multiprocessing library works by spawning additional Python processes.
They do not share memory.

I see you did import `Queue` from the multiprocessing library, but proceeded
not to use it. That `Queue` is one of two ways you can communicate between
`Process`es, the other being a `Pipe`.

Probably worthwhile to read through the
[documentation](https://docs.python.org/3.4/library/multiprocessing.html) for
the multiprocessing library before continuing.

