File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
core/base/dimensionReduction Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 1515using namespace std ;
1616using namespace ttk ;
1717
18+ DimensionReduction::~DimensionReduction ()
19+ {
20+ #ifdef TTK_ENABLE_SCIKIT_LEARN
21+ // If Python was not initialized by a still alive object.
22+ if (!this ->wasPythonInitialized_ ) {
23+ Py_Finalize ();
24+ }
25+ #endif
26+ }
27+
28+
29+
1830DimensionReduction::DimensionReduction () {
1931 this ->setDebugMsgPrefix (" DimensionReduction" );
2032
2133#ifdef TTK_ENABLE_SCIKIT_LEARN
22- auto finalize_callback = []() { Py_Finalize (); };
23-
2434 if (!Py_IsInitialized ()) {
35+ this ->wasPythonInitialized_ = false ;
2536 Py_Initialize ();
26- atexit (finalize_callback);
2737 }
2838
2939 const char *version = Py_GetVersion ();
Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ namespace ttk {
5656 public:
5757 DimensionReduction ();
5858
59+ ~DimensionReduction ();
60+
5961 /* * Scikit-Learn Dimension Reduction algorithms */
6062 enum class METHOD {
6163 /* * Spectral Embedding */
@@ -295,5 +297,8 @@ namespace ttk {
295297 int IsDeterministic{true };
296298 char majorVersion_{' 0' };
297299 bool IsInputADistanceMatrix{false };
300+
301+ private:
302+ bool wasPythonInitialized_{true };
298303 };
299304} // namespace ttk
You can’t perform that action at this time.
0 commit comments