GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — pythonnet/src/runtime/RuntimeState.cs at master · pythonnet/pythonnet Expand file tree/ Copy pathRuntimeState.csMore file actions 67 lines (60 loc) · 2 KB / Copy pathRuntimeState.csFile metadata and controls67 lines (60 loc) · 2 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 using System; using System.Collections.Generic; using System.Diagnostics; using static Python.Runtime.Runtime; namespace Python.Runtime { class RuntimeState { public static void Save() { if (!PySys_GetObject("initial_modules").IsNull) { throw new Exception("Runtime State set already"); } using var modules = PySet_New(default); int res = PySys_SetObject("initial_modules", modules.Borrow()); PythonException.ThrowIfIsNotZero(res); foreach (var name in GetModuleNames()) { res = PySet_Add(modules.Borrow(), new BorrowedReference(name)); PythonException.ThrowIfIsNotZero(res); } } public static void Restore() { RestoreModules(); } private static void RestoreModules() { var intialModules = PySys_GetObject("initial_modules"); Debug.Assert(!intialModules.IsNull); var modules = PyImport_GetModuleDict(); foreach (var nameRaw in GetModuleNames()) { var name = new BorrowedReference(nameRaw); if (PySet_Contains(intialModules, name) == 1) { continue; } if (PyDict_DelItem(modules, name) != 0) { PyErr_Print(); } } } public static IEnumerable<IntPtr> GetModuleNames() { var modules = PyImport_GetModuleDict(); using var names = PyDict_Keys(modules); nint length = PyList_Size(names.BorrowOrThrow()); if (length < 0) throw PythonException.ThrowLastAsClrException(); var result = new IntPtr[length]; for (int i = 0; i < length; i++) { result[i] = PyList_GetItem(names.Borrow(), i).DangerousGetAddress(); } return result; } } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |