Skip to content

Commit bc7aa20

Browse files
committed
fixed cached reference to inspect module stayed after shutdown
1 parent 6a0c1aa commit bc7aa20

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/runtime/runtime.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ internal static void Initialize(bool initSigs = false)
340340
PyList_Append(new BorrowedReference(path), item);
341341
XDecref(item);
342342
AssemblyManager.UpdatePath();
343+
344+
inspect = GetInspectModuleLazy();
343345
}
344346

345347
/// <summary>
@@ -431,6 +433,9 @@ internal static void Shutdown()
431433
Py_Finalize();
432434
}
433435

436+
private static Lazy<PyObject> GetInspectModuleLazy()
437+
=> new Lazy<PyObject>(() => PythonEngine.ImportModule("inspect"), isThreadSafe: false);
438+
434439
// called *without* the GIL acquired by clr._AtExit
435440
internal static int AtExit()
436441
{
@@ -509,8 +514,7 @@ public static PyObject None
509514
}
510515
}
511516

512-
private static readonly Lazy<PyObject> inspect =
513-
new Lazy<PyObject>(() => PythonEngine.ImportModule("inspect"), isThreadSafe: false);
517+
private static Lazy<PyObject> inspect;
514518
public static PyObject InspectModule => inspect.Value;
515519

516520
/// <summary>

0 commit comments

Comments
 (0)