msg196521 - (view) |
Author: Andrew Svetlov (asvetlov) * |
Date: 2013-08-30 10:26 |
We need public API for getting main thread object.
See also http://comments.gmane.org/gmane.comp.python.devel/141370
|
msg196526 - (view) |
Author: Christian Heimes (christian.heimes) * |
Date: 2013-08-30 12:29 |
The function must take care of fork() in worker threads, too. The isinstance(current_thread(), _MainThread) trick may not work.
|
msg196529 - (view) |
Author: Antoine Pitrou (pitrou) * |
Date: 2013-08-30 12:47 |
> 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:
- main_thread() returns the original _MainThread instance, even if it's
dead in the child process
- main_thread() returns the main thread of the current process
Both are reasonable, but we must settle for one :-)
(also, the use case of forking from a thread is really obscure, I don't
think we should worry too much about it)
|
msg196530 - (view) |
Author: Andrew Svetlov (asvetlov) * |
Date: 2013-08-30 12:48 |
Patch with code and tests is attached.
Test fails when program forks from thread other than the main one.
|
msg196531 - (view) |
Author: Andrew Svetlov (asvetlov) * |
Date: 2013-08-30 12:49 |
signal module reinitializes main_thread variable in PyOS_AfterFork, threading does nothing with forking.
|
msg196535 - (view) |
Author: Andrew Svetlov (asvetlov) * |
Date: 2013-08-30 13:30 |
http://bugs.python.org/issue16500 is required to make work after fork from thread other than the main one.
|
msg196540 - (view) |
Author: Antoine Pitrou (pitrou) * |
Date: 2013-08-30 13:56 |
> 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.
|
msg196615 - (view) |
Author: Andrew Svetlov (asvetlov) * |
Date: 2013-08-31 03:49 |
There is updated patch.
All tests pass.
I've added docs for threading.main_thread() function also.
|
msg196658 - (view) |
Author: Antoine Pitrou (pitrou) * |
Date: 2013-08-31 17:53 |
Ok, some comments about the patch (no "review" links appears so I'm gonna do it inline here):
- the doc addition needs a "versionadded" tag
- "The main thread is the thread that the OS creates to run application.": I would rephrase this "In normal conditions, the main thread is the thread from which the Python interpreter was started".
- in the tests:
+ self.assertEqual(data, "Thread-1\nTrue\nTrue\n")
Hmm, how do you know it will be called "Thread-1"?
I would give a specific name to the Thread, so as to make the test deterministic.
+ self.assertEqual(rc, 0)
You don't need this, it is already ensured by assert_python_ok().
- in threading.py, why doesn't _exitfunc() reuse the _main_thread global variable, instead of taking it as a parameter?
|
msg196707 - (view) |
Author: Andrew Svetlov (asvetlov) * |
Date: 2013-09-01 05:20 |
Uploaded new patch.
> - the doc addition needs a "versionadded" tag
Fixed.
> - "The main thread is the thread that the OS creates to run application.": I would rephrase this "In normal conditions, the main thread is the thread from which the Python interpreter was started".
Fixed.
> - in the tests:
> + self.assertEqual(data, "Thread-1\nTrue\nTrue\n")
>
> Hmm, how do you know it will be called "Thread-1"?
> I would give a specific name to the Thread, so as to make the test deterministic.
In this test main thread after forking is always first thread created by python. That's why it always is called 'Thread-1'.
> + self.assertEqual(rc, 0)
>
> You don't need this, it is already ensured by assert_python_ok().
Fixed.
> - in threading.py, why doesn't _exitfunc() reuse the _main_thread global variable, instead of taking it as a parameter?
Fixed.
|
msg196887 - (view) |
Author: Roundup Robot (python-dev) |
Date: 2013-09-04 04:01 |
New changeset 96e55a1a0de7 by Andrew Svetlov in branch 'default':
Issue #18882: Add threading.main_thread() function.
http://hg.python.org/cpython/rev/96e55a1a0de7
|
msg196894 - (view) |
Author: Antoine Pitrou (pitrou) * |
Date: 2013-09-04 06:26 |
I don't think you saw my review, but could you add a docstring to the main_thread() function? Thanks!
|
msg196895 - (view) |
Author: Andrew Svetlov (asvetlov) * |
Date: 2013-09-04 07:36 |
I did not received review email, sorry.
Docstring is added.
BTW 'threading' module has almost no docstrings, that's why I've added only docs at first.
Do you think docstrings should be added to all public functions?
Thanks.
|
msg196896 - (view) |
Author: Antoine Pitrou (pitrou) * |
Date: 2013-09-04 08:24 |
> BTW 'threading' module has almost no docstrings, that's why I've
> added only docs at first.
> Do you think docstrings should be added to all public functions?
Well, probably, although that's another issue :)
|
msg212053 - (view) |
Author: R. David Murray (r.david.murray) * |
Date: 2014-02-24 02:19 |
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.
|
msg212905 - (view) |
Author: Andrew Svetlov (asvetlov) * |
Date: 2014-03-07 22:21 |
Implementation uses the first choice:
main_thread() returns the original _MainThread instance, even if it's dead in the child process.
I'm sorry, would you guess desired documentation change?
|
|
Date |
User |
Action |
Args |
2022-04-11 14:57:50 | admin | set | github: 63082 |
2014-03-07 22:21:04 | asvetlov | set | messages:
+ msg212905 |
2014-02-24 02:19:48 | r.david.murray | set | nosy:
+ r.david.murray messages:
+ msg212053
|
2013-09-04 08:24:44 | pitrou | set | messages:
+ msg196896 |
2013-09-04 07:36:02 | asvetlov | set | messages:
+ msg196895 |
2013-09-04 06:26:23 | pitrou | set | messages:
+ msg196894 |
2013-09-04 04:08:19 | asvetlov | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
2013-09-04 04:01:25 | python-dev | set | nosy:
+ python-dev messages:
+ msg196887
|
2013-09-01 05:20:42 | asvetlov | set | files:
+ issue18882-4.diff
messages:
+ msg196707 |
2013-08-31 17:53:16 | pitrou | set | messages:
+ msg196658 |
2013-08-31 16:37:26 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka
type: enhancement components:
+ Library (Lib) stage: patch review |
2013-08-31 03:49:16 | asvetlov | set | files:
+ issue18882-2.diff
messages:
+ msg196615 |
2013-08-30 13:56:03 | pitrou | set | dependencies:
- Allow registering at-fork handlers messages:
+ msg196540 |
2013-08-30 13:30:05 | asvetlov | set | dependencies:
+ Allow registering at-fork handlers messages:
+ msg196535 |
2013-08-30 12:49:15 | asvetlov | set | messages:
+ msg196531 |
2013-08-30 12:48:17 | asvetlov | set | files:
+ issue18882.diff keywords:
+ patch messages:
+ msg196530
|
2013-08-30 12:47:11 | pitrou | set | messages:
+ msg196529 |
2013-08-30 12:45:07 | giampaolo.rodola | set | nosy:
+ giampaolo.rodola
|
2013-08-30 12:29:27 | christian.heimes | set | messages:
+ msg196526 |
2013-08-30 12:18:37 | christian.heimes | set | nosy:
+ christian.heimes
|
2013-08-30 10:26:46 | asvetlov | create | |