File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1022,12 +1022,18 @@ As we can easily check, our array is sorted now::
10221022 1 5 7 33 99
10231023 >>>
10241024
1025- **Important note for callback functions: **
1025+ **Important notes for callback functions: **
10261026
10271027Make sure you keep references to :func: `CFUNCTYPE ` objects as long as they are
10281028used from C code. :mod: `ctypes ` doesn't, and if you don't, they may be garbage
10291029collected, crashing your program when a callback is made.
10301030
1031+ Also, note that if the callback function is called in a thread created outside
1032+ of Python's control (e.g. by the foreign code that calls the callback), ctypes
1033+ creates a new dummy Python thread on every invocation. This behavior is correct
1034+ for most purposes, but it means that values stored with `threading.local ` will
1035+ *not * survive across different callbacks, even when those calls are made from
1036+ the same C thread.
10311037
10321038.. _ctypes-accessing-values-exported-from-dlls :
10331039
You can’t perform that action at this time.
0 commit comments