@@ -52,11 +52,20 @@ public static void DomainReloadAndGC()
5252 {
5353 Assert . IsFalse ( PythonEngine . IsInitialized ) ;
5454 RunAssemblyAndUnload ( "test1" ) ;
55-
5655 Assert . That ( Runtime . Runtime . Py_IsInitialized ( ) != 0 ,
5756 "On soft-shutdown mode, Python runtime should still running" ) ;
5857
5958 RunAssemblyAndUnload ( "test2" ) ;
59+ Assert . That ( Runtime . Runtime . Py_IsInitialized ( ) != 0 ,
60+ "On soft-shutdown mode, Python runtime should still running" ) ;
61+
62+ if ( PythonEngine . DefaultShutdownMode == ShutdownMode . Normal )
63+ {
64+ // The default mode is a normal mode,
65+ // it should shutdown the Python VM avoiding influence other tests.
66+ Runtime . Runtime . PyGILState_Ensure ( ) ;
67+ Runtime . Runtime . Py_Finalize ( ) ;
68+ }
6069 }
6170
6271 [ Test ]
@@ -268,17 +277,12 @@ public static void ShutdownPythonCompletely()
268277 // if it used a another mode(the default mode) in other tests,
269278 // when other tests trying to access these reserved objects, it may cause Domain exception,
270279 // thus it needs to reduct to Soft mode to make sure all clr objects remove from Python.
271- if ( PythonEngine . DefaultShutdownMode != ShutdownMode . Reload )
280+ var defaultMode = PythonEngine . DefaultShutdownMode ;
281+ if ( defaultMode != ShutdownMode . Reload )
272282 {
273- PythonEngine . ShutdownMode = ShutdownMode . Soft ;
283+ PythonEngine . ShutdownMode = defaultMode ;
274284 }
275285 PythonEngine . Shutdown ( ) ;
276- if ( PythonEngine . DefaultShutdownMode == ShutdownMode . Normal )
277- {
278- // Normal mode will shutdown the VM, so it needs to be shutdown
279- // for avoiding influence with other tests.
280- Runtime . Runtime . Shutdown ( ) ;
281- }
282286 }
283287
284288 public static IntPtr GetTestObject ( )
0 commit comments