New submission from pdox <p...@alum.mit.edu>:

Currently, Python exposes "thread identifiers" as unsigned long values across 
multiple modules:

threading.get_ident() -> Returns an integer thread id
sys._current_frames() -> Dictionary keys are integer thread ids
signal.pthread_kill() -> Accepts an arbitrary integer thread id

In reality, OS level thread identifiers are opaque types. On a system with 
pthreads, the thread_id that Python provides is merely pthread_t casted to 
unsigned long. This works today, but is in violation of the standard, and could 
break on systems with exotic pthread_t.

There is also the ability to introduce undefined behavior, such as sending a 
signal to an invalid thread id:

>>> signal.pthread_kill(42, signal.SIGHUP)
Segmentation fault (core dumped)

Changing the thread identifiers to an opaque type (which also tracks the 
validity of the thread id, for blocking use of expired system thread ids) will 
solve these two issues.

----------
components: Library (Lib)
messages: 303291
nosy: pdox
priority: normal
severity: normal
status: open
title: Make threading.get_ident() return an opaque type
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31622>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to