浏览代码

Suggestion: Give more multithreading flexibility

The Python interpreter can be constructed by any thread while the destructor is always the main thread. This can lead in some errors with the Python side of things, where some objects want the thread which constructed them to also destroy them. By adding this 'kill' function, a developer can use your library (btw gj! 👍 ) with `std::thread` in order to create a plot async -aka without blocking the main thread- and then close the plot and 'kill' Python interpreter afterwards, without waiting the program to end or having destructor errors.

Doing this in order to showcase this more. Small change but not that polished. Let me know about your opinion first and we can fix it 😃.
Thank you for your time and this great library ❤️
Le creepeur petitè 4 年之前
父节点
当前提交
b6f58a5c4c
共有 1 个文件被更改,包括 10 次插入0 次删除
  1. 10 0
      matplotlibcpp.h

+ 10 - 0
matplotlibcpp.h

@@ -108,7 +108,17 @@ struct _interpreter {
        */
 
     static _interpreter& get() {
+        return interkeeper(false);
+    }
+
+    static _interpreter& kill() {
+        return interkeeper(true);
+    }
+
+    static _interpreter& interkeeper(bool should_kill) {
         static _interpreter ctx;
+        if (should_kill)
+            ctx.~_interpreter();
         return ctx;
     }