From c79d22fde4d33094db0734caede094b247f2b8c7 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 17 Jan 2023 17:36:14 +0100 Subject: [PATCH] Ensure that `load` only runs once Fixes #2078. --- CHANGELOG.md | 3 ++- pythonnet/__init__.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2347895a8..94a85e094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. ### Fixed -- Fixed error occuring when inheriting a class containing a virtual generic method. +- Fixed error occuring when inheriting a class containing a virtual generic method. +- Make a second call to `pythonnet.load` a no-op, as it was intended. ## [3.0.1](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.1) - 2022-11-03 diff --git a/pythonnet/__init__.py b/pythonnet/__init__.py index 9d7b6c20a..5c1ca108a 100644 --- a/pythonnet/__init__.py +++ b/pythonnet/__init__.py @@ -120,7 +120,9 @@ def load(runtime: Union[clr_loader.Runtime, str, None] = None, **params: str) -> The same parameters as for `set_runtime` can be used. By default, `set_default_runtime` is called if no environment has been set yet and no - parameters are passed.""" + parameters are passed. + + After a successful call, further invocations will return immediately.""" global _LOADED, _LOADER_ASSEMBLY if _LOADED: @@ -142,6 +144,8 @@ def load(runtime: Union[clr_loader.Runtime, str, None] = None, **params: str) -> if func(b"") != 0: raise RuntimeError("Failed to initialize Python.Runtime.dll") + + _LOADED = True import atexit