-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Add threading.main_thread() function #63082
Comments
We need public API for getting main thread object. |
The function must take care of fork() in worker threads, too. The isinstance(current_thread(), _MainThread) trick may not work. |
Well, there are two possibilities:
Both are reasonable, but we must settle for one :-) (also, the use case of forking from a thread is really obscure, I don't |
Patch with code and tests is attached. |
signal module reinitializes main_thread variable in PyOS_AfterFork, threading does nothing with forking. |
http://bugs.python.org/issue16500 is required to make work after fork from thread other than the main one. |
No it isn't. Please take a look at _after_fork() in threading.py. |
There is updated patch. |
Ok, some comments about the patch (no "review" links appears so I'm gonna do it inline here):
Hmm, how do you know it will be called "Thread-1"? + self.assertEqual(rc, 0) You don't need this, it is already ensured by assert_python_ok().
|
Uploaded new patch.
|
New changeset 96e55a1a0de7 by Andrew Svetlov in branch 'default': |
I don't think you saw my review, but could you add a docstring to the main_thread() function? Thanks! |
I did not received review email, sorry. |
Well, probably, although that's another issue :) |
In msg196529 Antoine says there are two possible interpretations of main_thread, and we must choose one. However, the documentation does not indicate which one was chosen. |
Implementation uses the first choice: I'm sorry, would you guess desired documentation change? |
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: