0

I am hanging a little bit with the Threading. I would like to run a main programm and from there I want to start a Deamon - Thread and continuing in the mil programm.

Here is my code

class LEDStrip():
    def __init__(self):
         #init of LED

    def startLightcyclingThread(self):
        self.lightsdaemon = Thread(target=self.cycleMulticolorLights(), args=(), daemon=True, name='Background')
        self.lightsdaemon.start()

class Test():

def __init__(self):
        self.strip = LEDStrip()


def testfun(self):
        self.strip.startLightcyclingThread()    
        print("J")



def main():
    test = Test()
    test.testfun()

But I see the print out put only after the deamon is finished. How can I put the deamon in to Background and see the print output directly??

Thanks

test1
  • 95
  • 1
  • 7
  • 2
    You called the function passed as the `Thread`s target, rather than passing it. Change `target=self.cycleMulticolorLights()` to `target=self.cycleMulticolorLights`. There's a dupe for this somewhere, I'll find it. – ShadowRanger Nov 16 '22 at 17:55
  • Threads only run in the current instance (app). From what you wrote it appears you want a separate process that is not the same as the one you are testing. Threads and processes running as Daemons are very different things – ChrisSc Nov 16 '22 at 17:58
  • 2
    @ChrisSc: "daemon" in the context of a Python thread is a different beast from daemon processes (in some ways an opposite). Python daemon threads just means threads that are not considered when determining if the main process should exit (unlike C, where the end of the main thread means the end of the process, in Python, the process is only done when all non-daemon threads complete). Daemon processes keep running after their parent dies, Python daemon threads opt out of keeping the parent alive until they complete in the first place. – ShadowRanger Nov 16 '22 at 18:08

0 Answers0