mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
document that a new Python thread context is created in ctypes callbacks (closes #6627)
Patch by Nikolaus Rath.
This commit is contained in:
parent
e83ed43281
commit
f6ffb4b264
1 changed files with 7 additions and 1 deletions
|
@ -1022,12 +1022,18 @@ As we can easily check, our array is sorted now::
|
||||||
1 5 7 33 99
|
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
|
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
|
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.
|
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:
|
.. _ctypes-accessing-values-exported-from-dlls:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue