@@ -24,8 +24,11 @@ class base_subint {
2424 int svc_init () {
2525 TIMESTART (svc_init_start_time);
2626
27+ // associate a new thread state with fastflow node's thread
28+ PyThreadState* main_tstate = PyThreadState_New (tstate->interp );
29+
2730 // Hold the main GIL
28- PyEval_RestoreThread (tstate );
31+ PyEval_RestoreThread (main_tstate );
2932
3033 // Load pickling/unpickling functions but in the main interpreter
3134 pickling pickling_main;
@@ -43,9 +46,6 @@ class base_subint {
4346 // Cleanup of objects created
4447 pickling_main.~pickling ();
4548
46- // associate a new thread state with fastflow node's thread
47- tstate = PyThreadState_New (tstate->interp );
48-
4949 TIMESTART (svc_init_create_interpr);
5050
5151 // Create a new sub-interpreter with its own GIL
@@ -59,21 +59,22 @@ class base_subint {
5959 .gil = PyInterpreterConfig_OWN_GIL,
6060 };
6161 // save thread state with main interpreter
62- PyThreadState* cached_tstate = tstate ;
62+ PyThreadState* interp_tstate ;
6363 // create subinterpreter (and drop the main GIL and acquire the new GIL)
64- PyStatus status = Py_NewInterpreterFromConfig (&tstate , &sub_interp_config);
64+ PyStatus status = Py_NewInterpreterFromConfig (&interp_tstate , &sub_interp_config);
6565 /* The new interpreter is now active in the current thread */
6666 if (PyStatus_Exception (status)) {
6767 PRINT_ERROR (" Py_NewInterpreterFromConfig failure" )
6868 // cleanup thread state with main interpreter
69- PyThreadState_Clear (cached_tstate );
70- PyThreadState_Delete (cached_tstate );
69+ PyThreadState_Clear (main_tstate );
70+ PyThreadState_Delete (main_tstate );
7171 return -1 ;
7272 }
7373
74+ tstate = interp_tstate;
7475 // cleanup thread state with main interpreter
75- PyThreadState_Clear (cached_tstate );
76- PyThreadState_Delete (cached_tstate );
76+ PyThreadState_Clear (main_tstate );
77+ PyThreadState_Delete (main_tstate );
7778
7879 LOGELAPSED (" svc_init_create_interpr time " , svc_init_create_interpr);
7980
0 commit comments