#π What happens when a Thread goes out of scope?
14 messages Β· Page 1 of 1 (latest)
@hollow bridge
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
A thread will continue running until it's completed
So if it goes out of scope and never returns, it will just do it's thing, but also use memory?
yup
alright, thx
if you pass it the daemon flag it will be killed when your main application exits
so If I don't pass the flag, it will just exist further until I restart my pc?
hmmm....
A thread can be flagged as a "daemon thread". The significance of this flag is that the entire Python program exits when only daemon threads are left. The initial value is inherited from the creating thread.
meaning: if you got non-daemon threads, your python program stays alive, until all threads have finished, or you forcibly kill the process (which also kills the threads)
Generally best to avoid daemon threads, find some way to have the thread check an Event/flag so you can stop it running and join it
You can use a with ThreadPoolExecutor if you want to couple thread lifetimes to a scope
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.