|
@@ -103,8 +103,14 @@ struct _interpreter {
|
|
|
|
|
|
/* For now, _interpreter is implemented as a singleton since its currently not possible to have
|
|
|
multiple independent embedded python interpreters without patching the python source code
|
|
|
- or starting a separate process for each.
|
|
|
- http://bytes.com/topic/python/answers/793370-multiple-independent-python-interpreters-c-c-program
|
|
|
+ or starting a separate process for each. [1]
|
|
|
+ Furthermore, many python objects expect that they are destructed in the same thread as they
|
|
|
+ were constructed. [2] So for advanced usage, a `kill()` function is provided so that library
|
|
|
+ users can manually ensure that the interpreter is constructed and destroyed within the
|
|
|
+ same thread.
|
|
|
+
|
|
|
+ 1: http://bytes.com/topic/python/answers/793370-multiple-independent-python-interpreters-c-c-program
|
|
|
+ 2: https://github.com/lava/matplotlib-cpp/pull/202#issue-436220256
|
|
|
*/
|
|
|
|
|
|
static _interpreter& get() {
|
|
@@ -115,6 +121,7 @@ struct _interpreter {
|
|
|
return interkeeper(true);
|
|
|
}
|
|
|
|
|
|
+ // Stores the actual singleton object referenced by `get()` and `kill()`.
|
|
|
static _interpreter& interkeeper(bool should_kill) {
|
|
|
static _interpreter ctx;
|
|
|
if (should_kill)
|