[issue6627] threading.local() does not work with C-created threads

Nick Coghlan report at bugs.python.org
Sat Sep 18 04:20:38 CEST 2010


Nick Coghlan <ncoghlan at gmail.com> added the comment:

The suggestion in http://bugs.python.org/issue6627#msg116722 is a good one.

This a case where the user may legitimately not realise that threading.local is stored in the *temporary* state created by ctypes rather than in something more persistent inside the interpreter.

Since the ctypes state is per callback, it won't persist across calls, even when they're made from the same thread.

Suggested wording:
"""Note that if the callback function is called in a new thread that has been created outside of Python's control (i.e., by the foreign code that calls the callback), ctypes creates a new dummy Python thread on every invocation, including recreation of the thread local storage area. While this is correct for most purposes, it does mean that values stored with `threading.local` will *not* survive across different callbacks, even when those calls are made from the same C thread."""

----------
keywords: +easy
resolution: works for me -> 
stage: committed/rejected -> needs patch
status: closed -> open
type: behavior -> feature request

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


More information about the Python-bugs-list mailing list