[Python-Dev] Add function to signal module for getting main thread id (original) (raw)
Andrew Svetlov andrew.svetlov at gmail.com
Fri Aug 30 14:51:08 CEST 2013
- Previous message: [Python-Dev] Add function to signal module for getting main thread id
- Next message: [Python-Dev] Add function to signal module for getting main thread id
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I've made a patch. It works except scenario described by Christian Heimes. See details in http://bugs.python.org/issue18882
On Fri, Aug 30, 2013 at 3:21 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
Le Fri, 30 Aug 2013 14:06:11 +0200, Christian Heimes <christian at python.org> a écrit :
Am 30.08.2013 11:39, schrieb Antoine Pitrou: > > Le Fri, 30 Aug 2013 12:24:07 +0300, > Andrew Svetlov <andrew.svetlov at gmail.com> a écrit : >> Main thread is slightly different from others. >> Signals can be subscribed from main thread only. >> Tulip has special logic for main thread. >> In application code we can explicitly know which thread is >> executed, main or not. >> But from library it's not easy. >> Tulip uses check like >> threading.currentthread().name == 'MainThread' >> This approach has a problem: thread name is writable attribute and >> can be changed by user code. > > Please at least use: > > >>> isinstance(threading.currentthread(), threading.MainThread) > True > > But really, what we need is a threading.mainthread() function.
What happens, when a program fork()s from another thread than the main thread? AFAIR the other threads are suspended and the forking thread is the new main thread. Or something similar... Yes. We even support it :-) http://hg.python.org/cpython/file/c347b9063a9e/Lib/test/testthreading.py#l503 (well, whoever wrote that test wanted to support it. I don't think that's me) Regards Antoine.
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/andrew.svetlov%40gmail.com
-- Thanks, Andrew Svetlov
- Previous message: [Python-Dev] Add function to signal module for getting main thread id
- Next message: [Python-Dev] Add function to signal module for getting main thread id
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]