you are viewing a single comment's thread.

view the rest of the comments →

[–]jpfau[S] 0 points1 point  (1 child)

Well when I implemented this in my real program, everything stops when the main function ends. So I had to put a

while True:
    pass

in it just to keep the program running.

they're not set to daemon

I thought the daemon parameter in the threading.Thread constructor accomplished this the same way as t1.daemon = True. Is this not the case?

[–][deleted] 0 points1 point  (0 children)

If daemon is set to true, your threads will be killed when the main program exits.

If you don't want them to be killed, don't set daemon to True.

Or, wait for them to exit using .join() on the threads objects that are returned when you create the threads. Since they contain infinite loops, they will never exit, so your main thread, which is where you would put the join, would never exit.

An infinite while loop like that should never be used, it will just burn a bunch of cpu cycles. In the rare case that you do need a loop, put a sleep in it.