summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2025-07-15 13:32:55 +1000
committerDamien George <damien@micropython.org>2025-07-22 23:22:05 +1000
commit18f2e94846111ad05d49e260c59de366f3ae2489 (patch)
treeb3b51bb27958694ab3f97015bf059119ef54bed1 /docs
parente993f53877027bc46b226d026845e523c2cc94ca (diff)
py/modsys: Add sys.implementation._thread attribute.
This is useful to distinguish between GIL and non-GIL builds. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'docs')
-rw-r--r--docs/library/sys.rst10
1 files changed, 10 insertions, 0 deletions
diff --git a/docs/library/sys.rst b/docs/library/sys.rst
index baefd9270..cf8055217 100644
--- a/docs/library/sys.rst
+++ b/docs/library/sys.rst
@@ -77,6 +77,8 @@ Constants
* *_mpy* - supported mpy file-format version (optional attribute)
* *_build* - string that can help identify the configuration that
MicroPython was built with
+ * *_thread* - optional string attribute, exists if the target has threading
+ and is either "GIL" or "unsafe"
This object is the recommended way to distinguish MicroPython from other
Python implementations (note that it still may not exist in the very
@@ -95,6 +97,14 @@ Constants
* On microcontroller targets, the first element is the board name and the second
element (if present) is the board variant, for example ``'RPI_PICO2-RISCV'``
+ The *_thread* entry was added in version 1.26.0 and if it exists then the
+ target has the ``_thread`` module. If the target enables the GIL (global
+ interpreter lock) then this attribute is ``"GIL"``. Otherwise the attribute
+ is ``"unsafe"`` and the target has threading but does not enable the GIL,
+ and mutable Python objects (such as `bytearray`, `list` and `dict`) that are
+ shared amongst threads must be protected explicitly by locks such as
+ ``_thread.allocate_lock``.
+
.. admonition:: Difference to CPython
:class: attention