From f7ff20452c9e11a6dfa99c57f2ff9d038db29f2d Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Wed, 29 Jan 2025 14:46:37 +0100 Subject: [PATCH] Added a comment about GIL acquisition vs. multithreading vs. program exit. --- docs/api_core.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api_core.rst b/docs/api_core.rst index ccc2c89d..20efb711 100644 --- a/docs/api_core.rst +++ b/docs/api_core.rst @@ -2737,6 +2737,12 @@ running it in parallel from multiple Python threads. Reacquire the GIL +If you use nanobind in a multi-threaded program, you **must** ensure that +all threads have terminated **before** the interpreter exits. Otherwise any +code that re-acquires the GIL (e.g. for running destructors) will throw a +cancellation exception. This will result in a hard crash because C++ does +not support exceptions in destructors, nor ignoring a cancellation. + Free-threading --------------