New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A mechanism is needed to override waiting for Python threads to finish #54653
Comments
We use the Python interpreter embedded in our application, and would prefer to not block an exit of our application waiting for non-daemon threads to finish. I would like a mechanism exposed that queries for whether or not to wait. |
I have a patch here. |
Scratch that last patch. It was missing part of the fix. |
How do you use it? |
To use the callback, you can do this: import threading
def threadendcallback():
# return False to indicate that we don't
# want to wait for any threads before exiting
return False threading.currentThread().waitForThreadsOnExitFunc = threadendcallback |
Why is setting your threads as daemons not an option? |
Hey guys |
This looks like an ugly hack to solve a slightly exotic problem. You could instead enumerate() all threads and set their daemon flag to False, before shutting down the interpreter. |
Antoine wrote:
If it is intended to work this way, it should be mentioned in the documentation. Currently the documentation for "Thread.daemon" says: |
if self._started.is_set():
raise RuntimeError("cannot set daemon status of active thread") But still it looks like a code review problem: all your daemonic threads should be created as daemonic. Breaking the |
If nobody has nothing to add on this issue, I think it just should be closed. |
Given that this is from five years ago, and I've moved on, I honestly can't say I care too deeply about this. My use case was for handling threads:
I feel that my proposed change handles that in a reasonable way, and doesn't complicate the interface for threads terribly. Most users can completely ignore the new method I proposed, and it won't affect them. For those going to look for it, it'll be there. But again, I'm not even working in Python and no one else has chimed in on this in five years. Does it matter anymore?
|
Let's just close this. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: