8000 Suggestion: Give more multithreading flexibility · lava/matplotlib-cpp@b6f58a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b6f58a5

Browse files
thesmallcreeperlava
authored andcommitted
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 ❤️
1 parent dfe5a69 commit b6f58a5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

matplotlibcpp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,17 @@ struct _interpreter {
108108
*/
109109

110110
static _interpreter& get() {
111+
return interkeeper(false);
112+
}
113+
114+
static _interpreter& kill() {
115+
return interkeeper(true);
116+
}
117+
118+
static _interpreter& interkeeper(bool should_kill) {
111119
static _interpreter ctx;
120+
if (should_kill)
121+
ctx.~_interpreter();
112122
return ctx;
113123
}
114124

0 commit comments

Comments
 (0)
0