[Python-Dev] Add function to signal module for getting main thread id
andrew.svetlov at gmail.com
Fri Aug 30 12:27:15 CEST 2013
I've filed http://bugs.python.org/issue18882 for this.
On Fri, Aug 30, 2013 at 12:52 PM, Andrew Svetlov
<andrew.svetlov at gmail.com> wrote:
> _MainThread can be used as workaround, but adding public function makes value.
> Oleg, as I understand _MainThread is a class, not class instance, test
> for threading._MainThread.ident doesn't make sense.
> On Fri, Aug 30, 2013 at 12:44 PM, Oleg Broytman <phd at phdru.name> wrote:
>> On Fri, Aug 30, 2013 at 12:24:07PM +0300, Andrew Svetlov <andrew.svetlov at gmail.com> wrote:
>>> 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.current_thread().name == 'MainThread'
>>> This approach has a problem: thread name is writable attribute and can
>>> be changed by user code.
>> You can test
>> threading.current_thread().__class__ is threading._MainThread
>> threading.current_thread().ident == threading._MainThread.ident
>>> My proposition is to add function like get_mainthread_id() -> int
>>> which return ident for main thread
>> threading._MainThread.ident ?
>> Oleg Broytman http://phdru.name/ phd at phdru.name
>> Programmers don't die, they just GOSUB without RETURN.
>> Python-Dev mailing list
>> Python-Dev at python.org
>> Unsubscribe: http://mail.python.org/mailman/options/python-dev/andrew.svetlov%40gmail.com
> Andrew Svetlov
More information about the Python-Dev