[issue8197] Fatal error on thread creation in low memory condition (2)

STINNER Victor report at bugs.python.org
Mon Mar 22 02:08:25 CET 2010


New submission from STINNER Victor <victor.stinner at haypocalc.com>:

I wrote a patch to preallocate Python thread state before creating the thread to avoid a fatal error: issue7544 (it's now closed). This patch is not enough to avoid fatal errors in low memory condition.

Just after the creation of the thread, _PyGILState_NoteThreadState() is called. This function can fail with a fatal error (Couldn't create autoTLSkey mapping) in low memory condition if a memory allocation fails in find_key(), called by PyThread_set_key_value().

PyThread_set_key_value() fills a global single linked list of type 'struct key', the head is 'keyhead'. This list contains values and uses an index composed of (long thread id, int key). Only one key is used: autoTLSkey (0). The list is used to get the thread state (eg. in PyGILState_Ensure).

Note: This issue is very unlikely, but it does exist :-)

----------
messages: 101474
nosy: haypo
severity: normal
status: open
title: Fatal error on thread creation in low memory condition (2)
type: crash
versions: Python 2.7, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8197>
_______________________________________


More information about the Python-bugs-list mailing list