diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1022,12 +1022,20 @@ 1 5 7 33 99 >>> -**Important note for callback functions:** +**Important notes for callback functions:** Make sure you keep references to :func:`CFUNCTYPE` objects as long as they are used from C code. :mod:`ctypes` doesn't, and if you don't, they may be garbage collected, crashing your program when a callback is made. +Also 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. This behavior is correct for most purposes, but it means +that values stored with `threading.local` will *not* survive across +different callbacks, even when those calls are made from the same C +thread. .. _ctypes-accessing-values-exported-from-dlls: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -195,6 +195,9 @@ - Issue #19286: Directories in ``package_data`` are no longer added to the filelist, preventing failure outlined in the ticket. +- Issue #6627: Mention interaction with threading.local() in ctypes + documentation. Patch by Nikolaus Rath. + IDLE ----