diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-01-20 05:09:53 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-01-20 05:09:53 (GMT) |
commit | f6ffb4b264ae2ac3e9086abb8c825b195b207bff (patch) | |
tree | ad165a73e9b2500d37b7800e8b4785fd91fd12cb /Doc | |
parent | e83ed4328121747fc9b201497e3ebdaa43f90537 (diff) | |
download | cpython-f6ffb4b264ae2ac3e9086abb8c825b195b207bff.zip cpython-f6ffb4b264ae2ac3e9086abb8c825b195b207bff.tar.gz cpython-f6ffb4b264ae2ac3e9086abb8c825b195b207bff.tar.bz2 |
document that a new Python thread context is created in ctypes callbacks (closes #6627)
Patch by Nikolaus Rath.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/ctypes.rst | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index ae10b71..f001165 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -1022,12 +1022,18 @@ As we can easily check, our array is sorted now:: 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 thread created outside +of Python's control (e.g. by the foreign code that calls the callback), ctypes +creates a new dummy Python thread on every invocation. 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: |