Do threads automatically terminate when function complete?

title kinda says it all. here’s my example case:

if snfHasData():
    threading.Thread(target=sendSNFData, args=(0.10,), daemon=True).start()
    //do other stuff

basically, i just want to fire-and-forget this thread. have it run, do it’s business and then terminate itself. i don’t need anything back from the called function sendSNFData() and if it gets called again, it will be with a new payload of data that it sources from a global object.

will this do the do, or does it need handling when it’s done? i’m new to threading, so forgive me if this seems an obvious question. with an obvious answer; it’s isn’t so to me.

Yes the thread exits when the function finishes.
If you care that it has completed remove the daemon=True as that means the process can exit while the thread is still running.

1 Like

fantastic. thank you. things like this help to cement thread behaviour in my head.

1 Like