Skip to content

RuntimeError in 3.0.2 when calling set_runtime twice #2234

@bayerju-ey

Description

@bayerju-ey

Environment

  • Pythonnet version: 3.0.2
  • Python version: 3.8.17
  • Operating System: Linux (Debian 11)
  • .NET Runtime: netcoreapp3.1

Details

  • Describe what you were trying to get done.

I have two python modules. Each calls set_runtime and is sequentially imported by the same parent python file. The second import fails at set_runtime. This worked in 3.0.1 (and as far back as 3.0.0a2).

Each module includes the following lines of code:

from pythonnet import set_runtime
from clr_loader import get_coreclr
dir_name = os.path.dirname(__file__)
linux_config_path = os.path.join(dir_name, "pythonnet", "linux_config.json")
set_runtime(get_coreclr(runtime_config = linux_config_path))

linux_config.json contains the following:

{
  "runtimeOptions": {
    "tfm": "netcoreapp3.1",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "3.1.0"
    }
  }
}
  • If there was a crash, please include the traceback here.

The second import throws the following error:

Traceback (most recent call last):
  File "worker.py", line 4, in <module>
    from modules.job_launcher import JobLauncher
  File "/tmp/8dba270eb2712ba/deployment_platform/modules/job_launcher.py", line 25, in <module>
    from misc_dir.v2.v2 import V2
  File "/tmp/8dba270eb2712ba/deployment_platform/misc_dir/v2/v2.py", line 5, in <module>
    set_runtime(get_coreclr(runtime_config = linux_config_path))
  File "/tmp/8dba270eb2712ba/antenv/lib/python3.8/site-packages/pythonnet/__init__.py", line 26, in set_runtime
    raise RuntimeError(f"The runtime {_RUNTIME} has already been loaded")
RuntimeError: The runtime <clr_loader.hostfxr.DotnetCoreRuntime object at 0x77e5a37ba850> has already been loaded

Seems like this could be related to #2078/#2079, but that's just a guess.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions